Files
RelaisSMS/tests/Unit/PhoneNumberNormalizerTest.php

60 lines
2.1 KiB
PHP

<?php
namespace Tests\Unit;
use App\Contracts\PhoneNumberNormalizerInterface;
use Tests\TestCase;
class PhoneNumberNormalizerTest extends TestCase
{
public function test_it_normalizes_french_mobile_numbers_to_e164(): void
{
$result = app(PhoneNumberNormalizerInterface::class)->normalize('(+33) 6 11 11 00 02', 'FR');
$this->assertTrue($result->isValid);
$this->assertTrue($result->isMobile);
$this->assertSame('+33611110002', $result->normalizedNumber);
$this->assertSame('FR', $result->country);
$this->assertNull($result->error);
}
public function test_it_keeps_fixed_line_numbers_valid_but_not_mobile(): void
{
$result = app(PhoneNumberNormalizerInterface::class)->normalize('01 23 45 67 89', 'FR');
$this->assertTrue($result->isValid);
$this->assertFalse($result->isMobile);
$this->assertSame('+33123456789', $result->normalizedNumber);
}
public function test_it_detects_mobile_numbers_with_libphonenumber_when_regex_does_not_match(): void
{
config(['relais_sms.default_settings.mobile_phone_regex' => '/^never-matches$/']);
$result = app(PhoneNumberNormalizerInterface::class)->normalize('tel:+33611110002', 'FR');
$this->assertTrue($result->isValid);
$this->assertTrue($result->isMobile);
$this->assertSame('+33611110002', $result->normalizedNumber);
}
public function test_it_detects_dash_separated_french_mobile_numbers(): void
{
$result = app(PhoneNumberNormalizerInterface::class)->normalize('064-201-4207', 'FR');
$this->assertTrue($result->isValid);
$this->assertTrue($result->isMobile);
$this->assertSame('+33642014207', $result->normalizedNumber);
}
public function test_it_reports_invalid_numbers(): void
{
$result = app(PhoneNumberNormalizerInterface::class)->normalize('not a phone', 'FR');
$this->assertFalse($result->isValid);
$this->assertFalse($result->isMobile);
$this->assertNull($result->normalizedNumber);
$this->assertNotNull($result->error);
}
}