CachedReaderTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Doctrine\Tests\Common\Annotations;
  3. use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
  4. use Doctrine\Common\Annotations\AnnotationReader;
  5. use Doctrine\Common\Annotations\CachedReader;
  6. use Doctrine\Common\Cache\ArrayCache;
  7. class CachedReaderTest extends AbstractReaderTest
  8. {
  9. private $cache;
  10. public function testIgnoresStaleCache()
  11. {
  12. $file = __DIR__.'/Fixtures/Controller.php';
  13. touch($file);
  14. $name = 'Doctrine\Tests\Common\Annotations\Fixtures\Controller';
  15. $cacheKey = $name.'@[Annot]';
  16. $cache = $this->getMock('Doctrine\Common\Cache\Cache');
  17. $cache
  18. ->expects($this->at(0))
  19. ->method('fetch')
  20. ->with($this->equalTo($cacheKey))
  21. ->will($this->returnValue(array()))
  22. ;
  23. $cache
  24. ->expects($this->at(1))
  25. ->method('fetch')
  26. ->with($this->equalTo('[C]'.$cacheKey))
  27. ->will($this->returnValue(time() - 10))
  28. ;
  29. $cache
  30. ->expects($this->at(2))
  31. ->method('save')
  32. ->with($this->equalTo($cacheKey))
  33. ;
  34. $cache
  35. ->expects($this->at(3))
  36. ->method('save')
  37. ->with($this->equalTo('[C]'.$cacheKey))
  38. ;
  39. $reader = new CachedReader(new AnnotationReader(), $cache, true);
  40. $route = new Route();
  41. $route->pattern = '/someprefix';
  42. $this->assertEquals(array($route), $reader->getClassAnnotations(new \ReflectionClass($name)));
  43. }
  44. protected function getReader()
  45. {
  46. $this->cache = new ArrayCache();
  47. return new CachedReader(new AnnotationReader(), $this->cache);
  48. }
  49. }