Skip to content

Commit 080ea5a

Browse files
jschaedlfabpot
authored andcommitted
[Translator] Make sure a null locale is handled properly
1 parent cae08a0 commit 080ea5a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919

2020
class TranslatorTest extends TestCase
2121
{
22+
private $defaultLocale;
23+
24+
protected function setUp(): void
25+
{
26+
$this->defaultLocale = \Locale::getDefault();
27+
\Locale::setDefault('en');
28+
}
29+
30+
protected function tearDown(): void
31+
{
32+
\Locale::setDefault($this->defaultLocale);
33+
}
34+
2235
/**
2336
* @dataProvider getInvalidLocalesTests
2437
*/
@@ -45,7 +58,7 @@ public function testConstructorWithoutLocale()
4558
{
4659
$translator = new Translator(null);
4760

48-
$this->assertNull($translator->getLocale());
61+
$this->assertSame('en', $translator->getLocale());
4962
}
5063

5164
public function testSetGetLocale()
@@ -87,7 +100,7 @@ public function testSetNullLocale()
87100
$translator = new Translator('en');
88101
$translator->setLocale(null);
89102

90-
$this->assertNull($translator->getLocale());
103+
$this->assertSame('en', $translator->getLocale());
91104
}
92105

93106
public function testGetCatalogue()

src/Symfony/Component/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function setLocale($locale)
171171
*/
172172
public function getLocale()
173173
{
174-
return $this->locale;
174+
return $this->locale ?? \Locale::getDefault();
175175
}
176176

177177
/**

0 commit comments

Comments
 (0)