3 namespace Doctrine\Tests\Common\Annotations;
5 use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route;
6 use Doctrine\Common\Annotations\AnnotationReader;
7 use Doctrine\Common\Annotations\CachedReader;
8 use Doctrine\Common\Cache\ArrayCache;
10 class CachedReaderTest extends AbstractReaderTest
14 public function testIgnoresStaleCache()
16 $file = __DIR__.'/Fixtures/Controller.php';
18 $name = 'Doctrine\Tests\Common\Annotations\Fixtures\Controller';
19 $cacheKey = $name.'@[Annot]';
21 $cache = $this->getMock('Doctrine\Common\Cache\Cache');
23 ->expects($this->at(0))
25 ->with($this->equalTo($cacheKey))
26 ->will($this->returnValue(array()))
29 ->expects($this->at(1))
31 ->with($this->equalTo('[C]'.$cacheKey))
32 ->will($this->returnValue(time() - 10))
35 ->expects($this->at(2))
37 ->with($this->equalTo($cacheKey))
40 ->expects($this->at(3))
42 ->with($this->equalTo('[C]'.$cacheKey))
45 $reader = new CachedReader(new AnnotationReader(), $cache, true);
47 $route->pattern = '/someprefix';
48 $this->assertEquals(array($route), $reader->getClassAnnotations(new \ReflectionClass($name)));
51 protected function getReader()
53 $this->cache = new ArrayCache();
54 return new CachedReader(new AnnotationReader(), $this->cache);