*/ public static function normalizableNumbers(): iterable { yield 'mobile with punctuation' => ['(11) 98888-7777', '(11) 98888-7777']; yield 'mobile digits only' => ['11988887777', '(11) 98888-7777']; yield 'mobile with spaces and dashes' => ['11 98888 7777', '(11) 98888-7777']; yield 'mobile with +55 country code' => ['+55 11 98888-7777', '(11) 98888-7777']; yield 'mobile with bare 55 country code' => ['5511988887777', '(11) 98888-7777']; yield 'landline digits only' => ['1133334444', '(11) 3333-4444']; yield 'landline with punctuation' => ['(11) 3333-4444', '(11) 3333-4444']; yield 'padded with surrounding whitespace' => [" 11 98888-7777 \n", '(11) 98888-7777']; } #[DataProvider('normalizableNumbers')] public function test_it_normalizes_recognizable_brazilian_numbers(string $raw, string $expected): void { $this->assertSame($expected, BrazilianPhoneNumber::normalize($raw)); } /** * @return iterable */ public static function foreignOrImplausibleNumbers(): iterable { // 10-digit US number: DDD "20" has a '0' in the second position, // which no real Brazilian area code has. yield 'us number without country code' => ['2025551234']; // 11-digit US number with leading '1': DDD "12" is plausible, but // the third digit is '0', not the mandatory mobile '9'. yield 'us number with leading 1' => ['12025551234']; // 10-digit number with a DDD starting in '0', which cannot occur. yield 'ten digits with leading zero ddd' => ['0212345678']; // Explicit "+55" leaves only 9 digits behind — a mobile subscriber // number with no area code, not DDD 55. yield 'explicit country code missing ddd' => ['+55 98888-7777']; } #[DataProvider('foreignOrImplausibleNumbers')] public function test_it_preserves_numbers_that_are_not_plausibly_brazilian(string $raw): void { $this->assertSame($raw, BrazilianPhoneNumber::normalize($raw)); } public function test_it_still_formats_a_genuine_ddd_55_number(): void { // DDD 55 (Rio Grande do Sul) is a real area code and must not be // confused with the "+55" country code prefix handling above. $this->assertSame( '(55) 98888-7777', BrazilianPhoneNumber::normalize('(55) 98888-7777') ); } public function test_it_preserves_unrecognized_shapes_instead_of_discarding_information(): void { $this->assertSame( '+44 20 7946 0958', BrazilianPhoneNumber::normalize(' +44 20 7946 0958 ') ); } public function test_it_collapses_internal_whitespace_for_unrecognized_shapes(): void { $this->assertSame( 'ramal 123', BrazilianPhoneNumber::normalize("ramal 123\n") ); } public function test_it_preserves_annotations_next_to_a_recognizable_number(): void { $this->assertSame( '11 98888-7777 (WhatsApp)', BrazilianPhoneNumber::normalize('11 98888-7777 (WhatsApp)') ); } }