[Translator] Make sure a null locale is handled properly

This commit is contained in:
Jan Schädlich 2020-09-09 13:50:45 +02:00 committed by Fabien Potencier
parent cae08a0279
commit 080ea5a0f7
2 changed files with 16 additions and 3 deletions

View File

@ -19,6 +19,19 @@ use Symfony\Component\Translation\Translator;
class TranslatorTest extends TestCase
{
private $defaultLocale;
protected function setUp(): void
{
$this->defaultLocale = \Locale::getDefault();
\Locale::setDefault('en');
}
protected function tearDown(): void
{
\Locale::setDefault($this->defaultLocale);
}
/**
* @dataProvider getInvalidLocalesTests
*/
@ -45,7 +58,7 @@ class TranslatorTest extends TestCase
{
$translator = new Translator(null);
$this->assertNull($translator->getLocale());
$this->assertSame('en', $translator->getLocale());
}
public function testSetGetLocale()
@ -87,7 +100,7 @@ class TranslatorTest extends TestCase
$translator = new Translator('en');
$translator->setLocale(null);
$this->assertNull($translator->getLocale());
$this->assertSame('en', $translator->getLocale());
}
public function testGetCatalogue()

View File

@ -171,7 +171,7 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
*/
public function getLocale()
{
return $this->locale;
return $this->locale ?? \Locale::getDefault();
}
/**