Passed
Pull Request — master (#237)
by Joshua
43:42 queued 36:26
created

Issue21Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0
1
<?php
2
namespace libphonenumber\Tests\Issues;
3
4
use libphonenumber\PhoneNumberFormat;
5
use libphonenumber\PhoneNumberUtil;
6
7
class Issue21Test extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var PhoneNumberUtil
11
     */
12
    private $phoneUtil;
13
14
    public function setUp()
15
    {
16
        PhoneNumberUtil::resetInstance();
17
        $this->phoneUtil = PhoneNumberUtil::getInstance();
18
    }
19
20
    public function testFloatNumber()
21
    {
22
        $number = "0358112345678987";
23
        $phoneNumber = $this->phoneUtil->parse($number, "DE");
24
25
        $this->assertTrue($this->phoneUtil->isValidNumber($phoneNumber));
26
27
        $this->assertEquals('+49358112345678987', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::E164));
28
        $this->assertEquals('+49 3581 12345678987', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::INTERNATIONAL));
29
        $this->assertEquals('03581 12345678987', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::NATIONAL));
30
31
32
        $this->assertEquals('011 49 3581 12345678987', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'US'));
33
        $this->assertEquals('00 49 3581 12345678987', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'CH'));
34
    }
35
36
    public function testLongerNumber()
37
    {
38
        $number = "12345678901234567";
39
        $phoneNumber = $this->phoneUtil->parse($number, "DE");
40
41
        $this->assertEquals('+4912345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::E164));
42
        $this->assertEquals('+49 12345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::INTERNATIONAL));
43
        $this->assertEquals('12345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::NATIONAL));
44
45
46
        $this->assertEquals('011 49 12345678901234567', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'US'));
47
        $this->assertEquals('00 49 12345678901234567', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'CH'));
48
    }
49
}
50