diff --git a/src/Validator/PhoneNumber.php b/src/Validator/PhoneNumber.php index 26d2a789..f37f1e3f 100644 --- a/src/Validator/PhoneNumber.php +++ b/src/Validator/PhoneNumber.php @@ -154,7 +154,7 @@ public function getCountry() */ public function setCountry($country) { - $this->country = strtoupper($country); + $this->country = $country; return $this; } @@ -201,12 +201,12 @@ public function isValid($value = null, $context = null) $country = $this->getCountry(); - if (!$countryPattern = $this->loadPattern($country)) { + if (!$countryPattern = $this->loadPattern(strtoupper($country))) { if (isset($context[$country])) { $country = $context[$country]; } - if (!$countryPattern = $this->loadPattern($country)) { + if (!$countryPattern = $this->loadPattern(strtoupper($country))) { $this->error(self::UNSUPPORTED); return false; diff --git a/test/Validator/PhoneNumberTest.php b/test/Validator/PhoneNumberTest.php index f75c4753..ff19b565 100644 --- a/test/Validator/PhoneNumberTest.php +++ b/test/Validator/PhoneNumberTest.php @@ -3164,10 +3164,12 @@ public function testAllowPossibleSetterGetter() $this->assertTrue($this->validator->allowPossible()); } - public function testSetCountryMethodIsCaseInsensitive() + public function testCountryIsCaseInsensitive() { - $this->validator->setCountry('us'); - $this->assertSame('US', $this->validator->getCountry()); + $this->validator->setCountry('lt'); + $this->assertTrue($this->validator->isValid('+37067811268')); + $this->validator->setCountry('LT'); + $this->assertTrue($this->validator->isValid('+37067811268')); } /** @@ -3202,4 +3204,14 @@ public function testInvalidTypes($country, $code, $patterns) } } } + + public function testCanSpecifyCountryWithContext() + { + Locale::setDefault('ZW'); + $validator = new PhoneNumber([ + 'country' => 'country-code', + ]); + + $this->assertTrue($validator->isValid('+37067811268', ['country-code' => 'LT'])); + } }