Remaining tweaks for translator tests on 2.7
This are the remaining changes on the 2.7 branch after #14437 merged most of the improvements into 2.6.
This commit is contained in:
parent
4cc4f079c5
commit
c0300f57d5
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
|
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
|
||||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Translation\MessageSelector;
|
use Symfony\Component\Translation\MessageSelector;
|
||||||
@ -105,7 +104,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$translator->trans('foo');
|
$translator->trans('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadRessourcesWithCaching()
|
public function testLoadResourcesWithCaching()
|
||||||
{
|
{
|
||||||
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
||||||
$resourceFiles = array(
|
$resourceFiles = array(
|
||||||
@ -133,7 +132,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('folder', $translator->trans('folder'));
|
$this->assertEquals('folder', $translator->trans('folder'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadRessourcesWithoutCaching()
|
public function testLoadResourcesWithoutCaching()
|
||||||
{
|
{
|
||||||
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
|
||||||
$resourceFiles = array(
|
$resourceFiles = array(
|
||||||
@ -271,17 +270,20 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$catalogueHash = sha1(serialize(array(
|
|
||||||
'resources' => array(),
|
|
||||||
'fallback_locales' => array(),
|
|
||||||
)));
|
|
||||||
|
|
||||||
// prime the cache
|
// prime the cache
|
||||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml');
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml');
|
||||||
|
$translator->setLocale('fr');
|
||||||
$this->assertFalse(file_exists($this->tmpDir.'/catalogue.fr.'.$catalogueHash.'.php'));
|
|
||||||
$translator->warmup($this->tmpDir);
|
$translator->warmup($this->tmpDir);
|
||||||
$this->assertTrue(file_exists($this->tmpDir.'/catalogue.fr.'.$catalogueHash.'.php'));
|
|
||||||
|
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||||
|
$loader
|
||||||
|
->expects($this->never())
|
||||||
|
->method('load');
|
||||||
|
|
||||||
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml');
|
||||||
|
$translator->setLocale('fr');
|
||||||
|
$this->assertEquals('répertoire', $translator->trans('folder'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader')
|
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader')
|
||||||
|
@ -150,6 +150,32 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
|
|||||||
$translator->trans($msgid);
|
$translator->trans($msgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider runForDebugAndProduction
|
||||||
|
*/
|
||||||
|
public function testDifferentTranslatorsForSameLocaleDoNotInterfere($debug)
|
||||||
|
{
|
||||||
|
$locale = 'any_locale';
|
||||||
|
$format = 'some_format';
|
||||||
|
$msgid = 'test';
|
||||||
|
|
||||||
|
// Create a Translator and prime its cache
|
||||||
|
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||||
|
$translator->addLoader($format, new ArrayLoader());
|
||||||
|
$translator->addResource($format, array($msgid => 'FAIL'), $locale);
|
||||||
|
$translator->trans($msgid);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create another Translator with the same locale but a different resource.
|
||||||
|
* It should not use the first translator's cache but return the value from its own resource.
|
||||||
|
*/
|
||||||
|
$translator = new Translator($locale, null, $this->tmpDir, $debug);
|
||||||
|
$translator->addLoader($format, new ArrayLoader());
|
||||||
|
$translator->addResource($format, array($msgid => 'OK'), $locale);
|
||||||
|
|
||||||
|
$this->assertEquals('OK', $translator->trans($msgid), '-> different translators for the same domain interfere in '.($debug ? 'debug' : 'production'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider runForDebugAndProduction
|
* @dataProvider runForDebugAndProduction
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user