Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit080ea5a

Browse files
jschaedlfabpot
authored andcommitted
[Translator] Make sure a null locale is handled properly
1 parentcae08a0 commit080ea5a

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 TranslatorTestextends TestCase
2121
{
22+
private$defaultLocale;
23+
24+
protectedfunctionsetUp():void
25+
{
26+
$this->defaultLocale = \Locale::getDefault();
27+
\Locale::setDefault('en');
28+
}
29+
30+
protectedfunctiontearDown():void
31+
{
32+
\Locale::setDefault($this->defaultLocale);
33+
}
34+
2235
/**
2336
* @dataProvider getInvalidLocalesTests
2437
*/
@@ -45,7 +58,7 @@ public function testConstructorWithoutLocale()
4558
{
4659
$translator =newTranslator(null);
4760

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

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

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

93106
publicfunctiontestGetCatalogue()

‎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
publicfunctiongetLocale()
173173
{
174-
return$this->locale;
174+
return$this->locale ?? \Locale::getDefault();
175175
}
176176

177177
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp