@@ -100,4 +100,80 @@ public function testExtrasAnnotationWithScalar()
100
100
101
101
$ this ->loader ->load ($ content );
102
102
}
103
+
104
+ public function testCaching ()
105
+ {
106
+ // promises
107
+ $ annotations = $ this ->getMockBuilder ('Symfony\Cmf\Bundle\SeoBundle\Cache\CachedCollection ' )
108
+ ->disableOriginalConstructor ()
109
+ ->getMock ();
110
+ $ annotations
111
+ ->expects ($ this ->any ())
112
+ ->method ('isFresh ' )
113
+ ->will ($ this ->returnValue (true ))
114
+ ;
115
+ $ annotations
116
+ ->expects ($ this ->any ())
117
+ ->method ('getData ' )
118
+ ->will ($ this ->returnValue (['properties ' => [], 'methods ' => []]))
119
+ ;
120
+ $ cacheItemNoHit = $ this ->getMock ('Psr\Cache\CacheItemInterface ' );
121
+ $ cacheItemNoHit ->expects ($ this ->any ())->method ('isHit ' )->will ($ this ->returnValue (false ));
122
+ $ cacheItemNoHit ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ($ annotations ));
123
+ $ cacheItemHit = $ this ->getMock ('Psr\Cache\CacheItemInterface ' );
124
+ $ cacheItemHit ->expects ($ this ->any ())->method ('isHit ' )->will ($ this ->returnValue (true ));
125
+ $ cacheItemHit ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ($ annotations ));
126
+ $ cache = $ this ->getMock ('Psr\Cache\CacheItemPoolInterface ' );
127
+ $ cache
128
+ ->expects ($ this ->any ())
129
+ ->method ('getItem ' )
130
+ ->will ($ this ->onConsecutiveCalls ($ cacheItemNoHit , $ cacheItemHit ))
131
+ ;
132
+ $ loader = new AnnotationLoader (new AnnotationReader (), $ cache );
133
+
134
+ // predictions
135
+ $ cache
136
+ ->expects ($ this ->once ())
137
+ ->method ('save ' )
138
+ ;
139
+
140
+ $ loader ->load ($ this ->getContent ());
141
+ $ loader ->load ($ this ->getContent ());
142
+ }
143
+
144
+ public function testCacheRefresh ()
145
+ {
146
+ // promises
147
+ $ annotations = $ this ->getMockBuilder ('Symfony\Cmf\Bundle\SeoBundle\Cache\CachedCollection ' )
148
+ ->disableOriginalConstructor ()
149
+ ->getMock ();
150
+ $ annotations
151
+ ->expects ($ this ->any ())
152
+ ->method ('isFresh ' )
153
+ ->will ($ this ->returnValue (false ))
154
+ ;
155
+ $ annotations
156
+ ->expects ($ this ->any ())
157
+ ->method ('getData ' )
158
+ ->will ($ this ->returnValue (['properties ' => [], 'methods ' => []]))
159
+ ;
160
+ $ cacheItem = $ this ->getMock ('Psr\Cache\CacheItemInterface ' );
161
+ $ cacheItem ->expects ($ this ->any ())->method ('isHit ' )->will ($ this ->returnValue (true ));
162
+ $ cacheItem ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ($ annotations ));
163
+ $ cache = $ this ->getMock ('Psr\Cache\CacheItemPoolInterface ' );
164
+ $ cache
165
+ ->expects ($ this ->any ())
166
+ ->method ('getItem ' )
167
+ ->will ($ this ->returnValue ($ cacheItem ))
168
+ ;
169
+ $ loader = new AnnotationLoader (new AnnotationReader (), $ cache );
170
+
171
+ // predictions
172
+ $ cache
173
+ ->expects ($ this ->once ())
174
+ ->method ('save ' )
175
+ ;
176
+
177
+ $ loader ->load ($ this ->getContent ());
178
+ }
103
179
}
0 commit comments