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