Skip to content

Commit 3c3ee53

Browse files
Dont set the locale implicitly, just use the value provided by \Locale::getDefault() if none is set
Add tests Signed-off-by: Matthias Kühne <matthias.kuehne@ellerhold.de>
1 parent 3810313 commit 3c3ee53

6 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/View/Helper/CurrencyFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function setLocale($locale)
212212
public function getLocale()
213213
{
214214
if ($this->locale === null) {
215-
$this->locale = Locale::getDefault();
215+
return Locale::getDefault();
216216
}
217217

218218
return $this->locale;

src/View/Helper/DateFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function setLocale($locale)
9898
public function getLocale()
9999
{
100100
if ($this->locale === null) {
101-
$this->locale = Locale::getDefault();
101+
return Locale::getDefault();
102102
}
103103

104104
return $this->locale;

src/View/Helper/NumberFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function setLocale($locale)
214214
public function getLocale()
215215
{
216216
if ($this->locale === null) {
217-
$this->locale = Locale::getDefault();
217+
return Locale::getDefault();
218218
}
219219

220220
return $this->locale;

test/View/Helper/CurrencyFormatTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,16 @@ public static function assertMbStringEquals(string $expected, string $test, stri
108108
$test = str_replace(["\xC2\xA0", ' '], '', $test);
109109
self::assertEquals($expected, $test, $message);
110110
}
111+
112+
public function testNoImplicitLocale(): void
113+
{
114+
Locale::setDefault('de');
115+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
116+
117+
Locale::setDefault('en');
118+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
119+
120+
$this->helper->setLocale('es');
121+
self::assertEquals('es', $this->helper->getLocale());
122+
}
111123
}

test/View/Helper/DateFormatTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,16 @@ public function testIntlCalendarIsHandledAsWell(): void
295295
$helper->__invoke($calendar, IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'it_IT', 'dd-MM-Y')
296296
);
297297
}
298+
299+
public function testNoImplicitLocale(): void
300+
{
301+
Locale::setDefault('de');
302+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
303+
304+
Locale::setDefault('en');
305+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
306+
307+
$this->helper->setLocale('es');
308+
self::assertEquals('es', $this->helper->getLocale());
309+
}
298310
}

test/View/Helper/NumberFormatTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,16 @@ public static function assertMbStringEquals(string $expected, string $test, stri
196196
$test = str_replace(["\xC2\xA0", ' '], '', $test);
197197
self::assertEquals($expected, $test, $message);
198198
}
199+
200+
public function testNoImplicitLocale(): void
201+
{
202+
Locale::setDefault('de');
203+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
204+
205+
Locale::setDefault('en');
206+
self::assertEquals(Locale::getDefault(), $this->helper->getLocale());
207+
208+
$this->helper->setLocale('es');
209+
self::assertEquals('es', $this->helper->getLocale());
210+
}
199211
}

0 commit comments

Comments
 (0)