|
18 | 18 | use Symfony\Component\Config\Resource\FileExistenceResource;
|
19 | 19 | use Symfony\Component\Filesystem\Filesystem;
|
20 | 20 | use Symfony\Component\Translation\Formatter\MessageFormatter;
|
| 21 | +use Symfony\Component\Translation\Loader\YamlFileLoader; |
21 | 22 | use Symfony\Component\Translation\MessageCatalogue;
|
22 | 23 |
|
23 | 24 | class TranslatorTest extends TestCase
|
@@ -244,6 +245,41 @@ public function testCatalogResourcesAreAddedForScannedDirectories()
|
244 | 245 | $this->assertEquals(new FileExistenceResource('/tmp/I/sure/hope/this/does/not/exist'), $resources[2]);
|
245 | 246 | }
|
246 | 247 |
|
| 248 | + public function testCachedCatalogueIsReDumpedWhenScannedDirectoriesChange() |
| 249 | + { |
| 250 | + /** @var Translator $translator */ |
| 251 | + $translator = $this->getTranslator(new YamlFileLoader(), [ |
| 252 | + 'cache_dir' => $this->tmpDir, |
| 253 | + 'resource_files' => [ |
| 254 | + 'fr' => [ |
| 255 | + __DIR__.'/../Fixtures/Resources/translations/messages.fr.yml', |
| 256 | + ], |
| 257 | + ], |
| 258 | + 'scanned_directories' => [ |
| 259 | + __DIR__.'/../Fixtures/Resources/translations/', |
| 260 | + ], |
| 261 | + ], 'yml'); |
| 262 | + |
| 263 | + // Cached catalogue is dumped |
| 264 | + $this->assertSame('répertoire', $translator->trans('folder', [], 'messages', 'fr')); |
| 265 | + |
| 266 | + $translator = $this->getTranslator(new YamlFileLoader(), [ |
| 267 | + 'cache_dir' => $this->tmpDir, |
| 268 | + 'resource_files' => [ |
| 269 | + 'fr' => [ |
| 270 | + __DIR__.'/../Fixtures/Resources/translations/messages.fr.yml', |
| 271 | + __DIR__.'/../Fixtures/Resources/translations2/ccc.fr.yml', |
| 272 | + ], |
| 273 | + ], |
| 274 | + 'scanned_directories' => [ |
| 275 | + __DIR__.'/../Fixtures/Resources/translations/', |
| 276 | + __DIR__.'/../Fixtures/Resources/translations2/', |
| 277 | + ], |
| 278 | + ], 'yml'); |
| 279 | + |
| 280 | + $this->assertSame('bar', $translator->trans('foo', [], 'ccc', 'fr')); |
| 281 | + } |
| 282 | + |
247 | 283 | protected function getCatalogue($locale, $messages, $resources = [])
|
248 | 284 | {
|
249 | 285 | $catalogue = new MessageCatalogue($locale);
|
|
0 commit comments