Skip to content

Commit

Permalink
Merge pull request #36 from gsteel/fix/test-provider-generates-valid-…
Browse files Browse the repository at this point in the history
…numbers

Ensure `invalidPhoneNumberProvider` does not yield valid numbers
  • Loading branch information
gsteel authored Jul 1, 2024
2 parents 21d87e0 + 3100343 commit 34a5938
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion test/NumberGeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,29 @@ public static function validPhoneNumberProvider(): Generator
*/
public static function invalidPhoneNumberProvider(): Generator
{
$util = PhoneNumberUtil::getInstance();
$util = PhoneNumberUtil::getInstance();
$shortInfo = ShortNumberInfo::getInstance();

/** @var list<non-empty-string> $regions */
$regions = $util->getSupportedRegions();
foreach ($regions as $country) {
$number = $util->getInvalidExampleNumber($country);
if (! $number) {
continue;
}

if (
$util->isValidNumber($number)
||
$util->isValidNumberForRegion($number, $country)
||
$shortInfo->isValidShortNumber($number)
||
$shortInfo->isValidShortNumberForRegion($number, $country)
) {
continue;
}

$national = $number->getNationalNumber();
assert(is_string($national));

Expand Down

0 comments on commit 34a5938

Please sign in to comment.