NullPoolTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Elgg\Cache;
  3. use PHPUnit_Framework_TestCase as TestCase;
  4. class NullPoolTest extends TestCase implements PoolTestCase {
  5. public function testGetDoesNotRegenerateValueFromCallbackOnHit() {
  6. // NullPool never hits, so nothing to test here
  7. $this->assertTrue(true);
  8. }
  9. public function testGetRegeneratesValueFromCallbackOnMiss() {
  10. $pool = new NullPool();
  11. $result = $pool->get('foo', function() { return 1; });
  12. $this->assertEquals(1, $result);
  13. $result = $pool->get('foo', function() { return 2; });
  14. $this->assertEquals(2, $result);
  15. }
  16. public function testInvalidateForcesTheSpecifiedValueToBeRegenerated() {
  17. // All values are always regenerated. Nothing to test here...
  18. $this->assertTrue(true);
  19. }
  20. public function testNeverCachesResults() {
  21. $pool = new NullPool();
  22. $increment = function() {
  23. static $counter;
  24. if (!isset($counter)) {
  25. $counter = 0;
  26. }
  27. return $counter++;
  28. };
  29. $this->assertEquals(0, $pool->get('foo', $increment));
  30. $this->assertEquals(1, $pool->get('foo', $increment));
  31. $pool->put('foo', 4);
  32. $this->assertEquals(2, $pool->get('foo', $increment));
  33. $pool->invalidate('foo');
  34. $this->assertEquals(3, $pool->get('foo', $increment));
  35. }
  36. }