Skip to content

Commit 40999fd

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [HttpKernel] fixed a regression when no exception listeners are registered renamed some confusing tests propel/propel1 is now useless bumped Symfony version to 2.7.0 updated VERSION for 2.7.0-BETA1 updated CHANGELOG for 2.7.0-BETA1 [2.3] Fix @link annotations [2.7] For @link annotations [2.6] Fix @link annotations [2.7][Console] Count the array instead of [Config][cache factory] check type of callback argument. Fix javascript [2.3][Translation] test refresh cache when resources File change. Added deprecation message and original color back [Translator] Cache does not take fallback locales into consideration
2 parents 2a4942a + d0f9e60 commit 40999fd

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

Tests/Translation/TranslatorTest.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
1313

1414
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
15+
use Symfony\Component\Translation\Loader\ArrayLoader;
1516
use Symfony\Component\Translation\MessageCatalogue;
1617
use Symfony\Component\Filesystem\Filesystem;
1718
use Symfony\Component\Translation\MessageSelector;
@@ -77,6 +78,8 @@ public function testTransWithCaching()
7778

7879
// do it another time as the cache is primed now
7980
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
81+
$loader->expects($this->never())->method('load');
82+
8083
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
8184
$translator->setLocale('fr');
8285
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
@@ -90,6 +93,27 @@ public function testTransWithCaching()
9093
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
9194
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
9295
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
96+
97+
// refresh cache again when resource file resources file change
98+
$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+
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
108+
$loader
109+
->expects($this->at(0))
110+
->method('load')
111+
->will($this->returnValue($catalogue))
112+
;
113+
114+
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
115+
$translator->setLocale('fr');
116+
$this->assertEquals('foo fresh', $translator->trans('foo'));
93117
}
94118

95119
public function testTransWithCachingWithInvalidLocale()
@@ -227,12 +251,7 @@ protected function getContainer($loader)
227251

228252
public function getTranslator($loader, $options = array(), $loaderFomat = 'loader', $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator')
229253
{
230-
$translator = new $translatorClass(
231-
$this->getContainer($loader),
232-
new MessageSelector(),
233-
array($loaderFomat => array($loaderFomat)),
234-
$options
235-
);
254+
$translator = $this->createTranslator($loader, $options, $translatorClass, $loaderFomat);
236255

237256
if ('loader' === $loaderFomat) {
238257
$translator->addResource('loader', 'foo', 'fr');
@@ -267,6 +286,16 @@ public function testWarmup()
267286
$translator->warmup($this->tmpDir);
268287
$this->assertTrue(file_exists($this->tmpDir.'/catalogue.fr.'.$catalogueHash.'.php'));
269288
}
289+
290+
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader')
291+
{
292+
return new $translatorClass(
293+
$this->getContainer($loader),
294+
new MessageSelector(),
295+
array($loaderFomat => array($loaderFomat)),
296+
$options
297+
);
298+
}
270299
}
271300

272301
class TranslatorWithInvalidLocale extends Translator

0 commit comments

Comments
 (0)