1 | <?php |
||
9 | class Issue44Test extends \PHPUnit_Framework_TestCase |
||
10 | { |
||
11 | /** |
||
12 | * @var PhoneNumberUtil |
||
13 | */ |
||
14 | private $phoneUtil; |
||
15 | |||
16 | /** |
||
17 | * @var PhoneNumberOfflineGeocoder |
||
18 | */ |
||
19 | private $geocoder; |
||
20 | |||
21 | public function setUp() |
||
22 | { |
||
23 | PhoneNumberUtil::resetInstance(); |
||
24 | $this->phoneUtil = PhoneNumberUtil::getInstance(); |
||
25 | |||
26 | $this->geocoder = PhoneNumberOfflineGeocoder::getInstance(); |
||
27 | } |
||
28 | |||
29 | public function testMemoryUsageOfGeoLocationWithNoResult() |
||
30 | { |
||
31 | $number = $this->phoneUtil->parse("86-157-9662-1289", "CN"); |
||
32 | |||
33 | $startMemory = memory_get_usage(); |
||
34 | $location = $this->geocoder->getDescriptionForNumber($number, "en"); |
||
35 | $endMemory = memory_get_usage(); |
||
36 | |||
37 | $this->assertEquals("China", $location); |
||
38 | |||
39 | $memoryUsed = $endMemory - $startMemory; |
||
40 | |||
41 | $this->assertLessThan(5000000, $memoryUsed, "Memory usage should be below 5MB"); |
||
42 | } |
||
43 | |||
44 | public function testMemoryUsageOfGeoLocationWithResult() |
||
45 | { |
||
46 | $number = $this->phoneUtil->parse("86-131-2270-1411", "CN"); |
||
47 | |||
48 | $startMemory = memory_get_usage(); |
||
49 | $location = $this->geocoder->getDescriptionForNumber($number, "en"); |
||
50 | $endMemory = memory_get_usage(); |
||
51 | |||
52 | $this->assertEquals("Shanghai", $location); |
||
53 | |||
54 | $memoryUsed = $endMemory - $startMemory; |
||
55 | |||
56 | $this->assertLessThan(5000000, $memoryUsed, "Memory usage should be below 5MB"); |
||
57 | } |
||
58 | |||
59 | public function testChineseGeolocation() |
||
60 | { |
||
61 | $number = $this->phoneUtil->parse("+86 150 3657 7264", "CN"); |
||
62 | $location = $this->geocoder->getDescriptionForNumber($number, "en"); |
||
63 | |||
64 | $this->assertEquals("Luoyang, Henan", $location); |
||
65 | } |
||
66 | |||
67 | public function testChineseCarrierLookup() |
||
68 | { |
||
69 | $number = $this->phoneUtil->parse("+86 150 3657 7264", "CN"); |
||
70 | |||
71 | $carrier = PhoneNumberToCarrierMapper::getInstance(); |
||
72 | |||
73 | $location = $carrier->getNameForNumber($number, "en"); |
||
74 | |||
75 | $this->assertEquals("China Mobile", $location); |
||
76 | } |
||
77 | } |
||
78 |