forked from ckdarby/php-geocode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeocodeTest.php
executable file
·110 lines (96 loc) · 3.28 KB
/
GeocodeTest.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace KamranAhmed\Geocode;
class GeocodeTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerTestGeocodeProvider
*/
public function testGeocode($address, $expected)
{
$actual = new Geocode();
$location = $actual->get($address);
$methods = array_keys($expected);
$this->assertTrue($location->isValid());
foreach ($methods as $method) {
$this->assertEquals($expected[$method], $location->$method());
}
}
public function testInvalidLocation()
{
$geo = new Geocode();
$location = $geo->get("House of the rights for the poor people");
$this->assertFalse($location->isValid());
}
/**
* @test
* @expectedException \Exception
* @expectedExceptionMessage Address is required in order to process
*/
public function testEmptyOrNullAdress()
{
$actual = new Geocode();
$actual->get("");
}
public function testGeocodeProtocol()
{
$actual = new Geocode();
$this->assertEquals(
'http://maps.googleapis.com/maps/api/geocode/json?',
$actual->getServiceUrl()
);
$actual = new Geocode();
$this->assertEquals(
'http://maps.googleapis.com/maps/api/geocode/json?',
$actual->getServiceUrl()
);
}
public function testGeocodeKey()
{
$actual = new Geocode('DUMMYKEY');
$this->assertEquals(
'https://maps.googleapis.com/maps/api/geocode/json?key=DUMMYKEY',
$actual->getServiceUrl()
);
$actual = new Geocode('DUMMYKEY');
$this->assertEquals(
'https://maps.googleapis.com/maps/api/geocode/json?key=DUMMYKEY',
$actual->getServiceUrl()
);
}
public function providerTestGeocodeProvider()
{
$providers = [];
$providers[] = [
"1600 Amphitheatre Parkway, Mountain View, CA",
[
'getAddress' => '1600 Amphitheatre Parkway, Mountain View, CA',
'getCountry' => 'United States',
'getShortCountry' => 'US',
'getLocality' => 'Mountain View',
'getShortLocality' => 'Mountain View',
'getDistrict' => 'California',
'getShortDistrict' => 'CA',
'getPostcode' => '94043',
'getStreetAddress' => 'Amphitheatre Parkway',
'getShortStreetAddress' => 'Amphitheatre Pkwy',
'getStreetNumber' => '1600',
],
];
$providers[] = [
"9 Little St, Beachburg, Ontario, Canada",
[
'getAddress' => '9 Little St, Beachburg, Ontario, Canada',
'getCountry' => 'Canada',
'getShortCountry' => 'CA',
'getLocality' => 'Beachburg',
'getShortLocality'=> 'Beachburg',
'getDistrict' => 'Ontario',
'getShortDistrict'=> 'ON',
'getPostcode' => 'K0J 1C0',
'getTown' => '',
'getStreetNumber' => '9',
],
];
return $providers;
}
}