From 55f0c1694d7f7ddad512e82d415674c4c6ac5c8c Mon Sep 17 00:00:00 2001 From: Holger Veltrup Date: Mon, 29 Apr 2024 13:56:43 +0200 Subject: [PATCH] fix: === comparison with default lang --- src/ResourceLanguage.php | 2 +- test/ResourceLanguageTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ResourceLanguage.php b/src/ResourceLanguage.php index 26a3525..6d3070c 100644 --- a/src/ResourceLanguage.php +++ b/src/ResourceLanguage.php @@ -23,7 +23,7 @@ public static function default(): self public static function of(?string $str): self { if ($str === null || empty($str)) { - return new self(''); + return self::default(); } $code = Locale::getPrimaryLanguage($str); return new self($code); diff --git a/test/ResourceLanguageTest.php b/test/ResourceLanguageTest.php index 02f47f1..3cc3e35 100644 --- a/test/ResourceLanguageTest.php +++ b/test/ResourceLanguageTest.php @@ -17,6 +17,15 @@ public function testDefault(): void $this->assertSame('', $language->code); } + public function testEqualsDefault(): void + { + $lang = ResourceLanguage::of(''); + $this->assertTrue( + ResourceLanguage::default() === $lang, + 'empty lang should be equals to default lang' + ); + } + public function testOfOnlyLang(): void { $language = ResourceLanguage::of('en');