File: RegionCodeCaseInsensitiveTest.php

package info (click to toggle)
php-giggsey-libphonenumber 9.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,464 kB
  • sloc: php: 484,879; sh: 107; makefile: 37
file content (83 lines) | stat: -rw-r--r-- 2,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

declare(strict_types=1);

namespace libphonenumber\Tests\Issues;

use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
use libphonenumber\ShortNumberInfo;
use PHPUnit\Framework\TestCase;
use libphonenumber\PhoneMetadata;

class RegionCodeCaseInsensitiveTest extends TestCase
{
    private PhoneNumberUtil $phoneUtil;

    private ShortNumberInfo $shortInfo;

    public function setUp(): void
    {
        PhoneNumberUtil::resetInstance();
        $this->phoneUtil = PhoneNumberUtil::getInstance();
        $this->shortInfo = ShortNumberInfo::getInstance();
    }

    public function testParse(): void
    {
        $number = '07987458147';
        $phoneObject = $this->phoneUtil->parse($number, 'gb');

        self::assertTrue($this->phoneUtil->isValidNumber($phoneObject));

        self::assertTrue($this->phoneUtil->isValidNumberForRegion($phoneObject, 'gb'));
    }

    public function testIsNANPACountry(): void
    {
        self::assertTrue($this->phoneUtil->isNANPACountry('us'));
    }

    public function testGetMetadataForRegion(): void
    {
        $metadata = $this->phoneUtil->getMetadataForRegion('gb');

        self::assertInstanceOf(PhoneMetadata::class, $metadata);
    }

    public function testConnectsToEmergency(): void
    {
        self::assertTrue($this->shortInfo->connectsToEmergencyNumber('911', 'us'));
        self::assertFalse($this->shortInfo->connectsToEmergencyNumber('9111', 'br'));
    }

    public function testGetCountryCodeForRegion(): void
    {
        self::assertSame(44, $this->phoneUtil->getCountryCodeForRegion('gb'));
    }

    public function testExampleNumber(): void
    {
        self::assertSame(
            (string) $this->phoneUtil->parse('+441212345678'),
            (string) $this->phoneUtil->getExampleNumber('gb')
        );
        self::assertSame(
            (string) $this->phoneUtil->parse('+44121234567'),
            (string) $this->phoneUtil->getInvalidExampleNumber('gb')
        );
        self::assertSame(
            (string) $this->phoneUtil->parse('+447400123456'),
            (string) $this->phoneUtil->getExampleNumberForType('gb', PhoneNumberType::MOBILE)
        );
    }

    public function testFindNumbers(): void
    {
        $phoneNumberMatcher = $this->phoneUtil->findNumbers('Testing 01212345678', 'gb');

        $phoneNumberMatcher->next();
        $match = $phoneNumberMatcher->current();
        self::assertNotNull($match);
    }
}