@@ -93,27 +93,27 @@ public function testTransWithCaching()
93
93
$ this ->assertEquals ('other choice 1 (PT-BR) ' , $ translator ->transChoice ('other choice ' , 1 ));
94
94
$ this ->assertEquals ('foobarbaz (fr.UTF-8) ' , $ translator ->trans ('foobarbaz ' ));
95
95
$ this ->assertEquals ('foobarbax (sr@latin) ' , $ translator ->trans ('foobarbax ' ));
96
+ }
96
97
97
- // refresh cache again when resource file resources file change
98
+ public function testRefreshCacheWhenResourcesAreNoLongerFresh ()
99
+ {
98
100
$ resource = $ this ->getMock ('Symfony\Component\Config\Resource\ResourceInterface ' );
99
- $ resource
100
- ->expects ($ this ->at (0 ))
101
- ->method ('isFresh ' )
102
- ->will ($ this ->returnValue (false ))
103
- ;
104
- $ catalogue = $ this ->getCatalogue ('fr ' , array ('foo ' => 'foo fresh ' ));
105
- $ catalogue ->addResource ($ resource );
106
-
107
101
$ loader = $ this ->getMock ('Symfony\Component\Translation\Loader\LoaderInterface ' );
102
+ $ resource ->method ('isFresh ' )->will ($ this ->returnValue (false ));
108
103
$ loader
109
- ->expects ($ this ->at ( 0 ))
104
+ ->expects ($ this ->exactly ( 2 ))
110
105
->method ('load ' )
111
- ->will ($ this ->returnValue ($ catalogue ))
112
- ;
106
+ ->will ($ this ->returnValue ($ this ->getCatalogue ('fr ' , array (), array ($ resource ))));
113
107
114
- $ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir ));
108
+ // prime the cache
109
+ $ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir , 'debug ' => true ));
115
110
$ translator ->setLocale ('fr ' );
116
- $ this ->assertEquals ('foo fresh ' , $ translator ->trans ('foo ' ));
111
+ $ translator ->trans ('foo ' );
112
+
113
+ // prime the cache second time
114
+ $ translator = $ this ->getTranslator ($ loader , array ('cache_dir ' => $ this ->tmpDir , 'debug ' => true ));
115
+ $ translator ->setLocale ('fr ' );
116
+ $ translator ->trans ('foo ' );
117
117
}
118
118
119
119
public function testTransWithCachingWithInvalidLocale ()
@@ -235,12 +235,15 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales(
235
235
$ this ->assertEquals ('bar ' , $ translator ->trans ('bar ' ));
236
236
}
237
237
238
- protected function getCatalogue ($ locale , $ messages )
238
+ protected function getCatalogue ($ locale , $ messages, $ resources = array () )
239
239
{
240
240
$ catalogue = new MessageCatalogue ($ locale );
241
241
foreach ($ messages as $ key => $ translation ) {
242
242
$ catalogue ->set ($ key , $ translation );
243
243
}
244
+ foreach ($ resources as $ resource ) {
245
+ $ catalogue ->addResource ($ resource );
246
+ }
244
247
245
248
return $ catalogue ;
246
249
}
0 commit comments