Skip to content

Commit

Permalink
Add PhoneNumber::isEqualTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Aug 5, 2021
1 parent 51140a5 commit a4d57ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public function formatForCallingFrom(string $regionCode) : string
return PhoneNumberUtil::getInstance()->formatOutOfCountryCallingNumber($this->phoneNumber, $regionCode);
}

public function isEqualTo(PhoneNumber $phoneNumber): bool
{
return $this->phoneNumber->equals($phoneNumber->phoneNumber);
}

/**
* Returns a string representation of this phone number in international E164 format.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,25 @@ public function providerGetGeographicalAreaCode() : array
['+33567000000', '5'],
];
}

/**
* @dataProvider providerIsEqualTo
*/
public function testIsEqualTo(string $phoneNumber1, string $phoneNumber2, bool $isEqual): void
{
$phoneNumber1 = PhoneNumber::parse($phoneNumber1);
$phoneNumber2 = PhoneNumber::parse($phoneNumber2);

echo "$phoneNumber2\n";

self::assertSame($isEqual, $phoneNumber1->isEqualTo($phoneNumber2));
}

public function providerIsEqualTo(): array
{
return [
['+442079460585', '+442079460585', true],
['+442079460585', '+442079460586', false],
];
}
}

0 comments on commit a4d57ff

Please sign in to comment.