From 04b8e4e77ec1f48a4845e68e08dc979316f9e6c7 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Tue, 14 Apr 2015 08:53:08 +0100 Subject: [PATCH] [Translation][fixed test] refresh cache when resources are no longer fresh. --- .../Tests/Translation/TranslatorTest.php | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php index 5c2ab2c9cc45..3617d3858a85 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php @@ -93,27 +93,27 @@ public function testTransWithCaching() $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); $this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz')); $this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax')); + } - // refresh cache again when resource file resources file change + public function testRefreshCacheWhenResourcesAreNoLongerFresh() + { $resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface'); - $resource - ->expects($this->at(0)) - ->method('isFresh') - ->will($this->returnValue(false)) - ; - $catalogue = $this->getCatalogue('fr', array('foo' => 'foo fresh')); - $catalogue->addResource($resource); - $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $resource->method('isFresh')->will($this->returnValue(false)); $loader - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('load') - ->will($this->returnValue($catalogue)) - ; + ->will($this->returnValue($this->getCatalogue('fr', array(), array($resource)))); - $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir)); + // prime the cache + $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true)); $translator->setLocale('fr'); - $this->assertEquals('foo fresh', $translator->trans('foo')); + $translator->trans('foo'); + + // prime the cache second time + $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'debug' => true)); + $translator->setLocale('fr'); + $translator->trans('foo'); } public function testTransWithCachingWithInvalidLocale() @@ -235,12 +235,15 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales( $this->assertEquals('bar', $translator->trans('bar')); } - protected function getCatalogue($locale, $messages) + protected function getCatalogue($locale, $messages, $resources = array()) { $catalogue = new MessageCatalogue($locale); foreach ($messages as $key => $translation) { $catalogue->set($key, $translation); } + foreach ($resources as $resource) { + $catalogue->addResource($resource); + } return $catalogue; }