[Translation] deprecate passing a null locale
This commit is contained in:
parent
6811aaa8e0
commit
088615ddaf
@ -32,6 +32,10 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
*/
|
||||
public function __construct(?string $locale, array $messages = [])
|
||||
{
|
||||
if (null === $locale) {
|
||||
@trigger_error(sprintf('Passing "null" to the first argument of the "%s" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->locale = $locale;
|
||||
$this->messages = $messages;
|
||||
}
|
||||
|
@ -23,6 +23,17 @@ class MessageCatalogueTest extends TestCase
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Passing "null" to the first argument of the "Symfony\Component\Translation\MessageCatalogue::__construct" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.
|
||||
*/
|
||||
public function testGetNullLocale()
|
||||
{
|
||||
$catalogue = new MessageCatalogue(null);
|
||||
|
||||
$this->assertNull($catalogue->getLocale());
|
||||
}
|
||||
|
||||
public function testGetDomains()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => [], 'domain2' => [], 'domain2+intl-icu' => [], 'domain3+intl-icu' => []]);
|
||||
|
@ -184,12 +184,25 @@ class TranslatorTest extends TestCase
|
||||
*/
|
||||
public function testAddResourceValidLocales($locale)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$this->markTestSkipped('null is not a valid locale');
|
||||
}
|
||||
$translator = new Translator('fr');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], $locale);
|
||||
// no assertion. this method just asserts that no exception is thrown
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Passing "null" to the third argument of the "Symfony\Component\Translation\Translator::addResource" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.
|
||||
*/
|
||||
public function testAddResourceNull()
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
$translator->addResource('array', ['foo' => 'foofoo'], null);
|
||||
}
|
||||
|
||||
public function testAddResourceAfterTrans()
|
||||
{
|
||||
$translator = new Translator('fr');
|
||||
@ -367,10 +380,13 @@ class TranslatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidLocalesTests
|
||||
* @dataProvider getValidLocalesTests
|
||||
*/
|
||||
public function testTransValidLocale($locale)
|
||||
{
|
||||
if (null === $locale) {
|
||||
$this->markTestSkipped('null is not a valid locale');
|
||||
}
|
||||
$translator = new Translator($locale);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', ['test' => 'OK'], $locale);
|
||||
@ -379,6 +395,17 @@ class TranslatorTest extends TestCase
|
||||
$this->assertEquals('OK', $translator->trans('test', [], null, $locale));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Passing "null" to the third argument of the "Symfony\Component\Translation\Translator::addResource" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.
|
||||
*/
|
||||
public function testTransNullLocale()
|
||||
{
|
||||
$translator = new Translator(null);
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', ['test' => 'OK'], null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getFlattenedTransTests
|
||||
*/
|
||||
|
@ -132,6 +132,10 @@ class Translator implements LegacyTranslatorInterface, TranslatorInterface, Tran
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
||||
if (null === $locale) {
|
||||
@trigger_error(sprintf('Passing "null" to the third argument of the "%s" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->assertValidLocale($locale);
|
||||
|
||||
$this->resources[$locale][] = [$format, $resource, $domain];
|
||||
|
Reference in New Issue
Block a user