MemoryPoolTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Elgg\Cache;
  3. use PHPUnit_Framework_TestCase as TestCase;
  4. class MemoryPoolTest extends TestCase implements PoolTestCase {
  5. public function testGetDoesNotRegenerateValueFromCallbackOnHit() {
  6. $pool = new MemoryPool();
  7. $pool->get('foo', function() { return 1; });
  8. $result = $pool->get('foo', function() { return 2; });
  9. $this->assertEquals(1, $result);
  10. }
  11. public function testGetRegeneratesValueFromCallbackOnMiss() {
  12. $pool = new MemoryPool();
  13. $result = $pool->get('foo', function() { return 1; });
  14. $this->assertEquals(1, $result);
  15. }
  16. public function testInvalidateForcesTheSpecifiedValueToBeRegenerated() {
  17. $pool = new MemoryPool();
  18. $result = $pool->get('foo', function() { return 1; });
  19. $this->assertEquals(1, $result);
  20. $pool->invalidate('foo');
  21. $result = $pool->get('foo', function() { return 2; });
  22. $this->assertEquals(2, $result);
  23. }
  24. public function testPutOverridesGetCallback() {
  25. $pool = new MemoryPool();
  26. $result = $pool->get('foo', function() { return 1; });
  27. $this->assertEquals(1, $result);
  28. $pool->put('foo', 2);
  29. $result = $pool->get('foo', function() { return 3; });
  30. $this->assertEquals(2, $result);
  31. }
  32. }