8000 [Translation][fixed test] refresh cache when resources are no longer … · symfony/symfony@04b8e4e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 04b8e4e

Browse files
committed
[Translation][fixed test] refresh cache when resources are no longer fresh.
1 parent 5d428b7 commit 04b8e4e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ public function testTransWithCaching()
9393
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
9494
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
9595
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
96+
}
9697

97-
// refresh cache again when resource file resources file change
98+
public function testRefreshCacheWhenResourcesAreNoLongerFresh()
99+
{
98100
$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-
107101
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
102+
$resource->method('isFresh')->will($this->returnValue(false));
108103
$loader
109-
->expects($this->at(0))
104+
->expects($this->exactly(2))
110105
->method('load')
111-
->will($this->returnValue($catalogue))
112-
;
106+
->will($this->returnValue($this->getCatalogue('fr', array(), array($resource))));
113107

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));
115110
$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');
117117
}
118118

119119
public function testTransWithCachingWithInvalidLocale()
@@ -235,12 +235,15 @@ public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales(
235235
$this->assertEquals('bar', $translator->trans('bar'));
236236
}
237237

238-
protected function getCatalogue($locale, $messages)
238+
protected function getCatalogue($locale, $messages, $resources = array())
239239
{
240240
$catalogue = new MessageCatalogue($locale);
241241
foreach ($messages as $key => $translation) {
242242
$catalogue->set($key, $translation);
243243
}
244+
foreach ($resources as $resource) {
245+
$catalogue->addResource($resource);
246+
}
244247

245248
return $catalogue;
246249
}

0 commit comments

Comments
 (0)
0