@@ -16,16 +16,16 @@ |
||
| 16 | 16 | |
| 17 | 17 | class GoogleMapsApiTest extends TestCase { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @test |
|
| 21 | - */ |
|
| 22 | - public function checkApiKeyTest() { |
|
| 19 | + /** |
|
| 20 | + * @test |
|
| 21 | + */ |
|
| 22 | + public function checkApiKeyTest() { |
|
| 23 | 23 | |
| 24 | - $gm = new GoogleMapsApi([ |
|
| 25 | - GoogleMapsApiConfigFields::SERVICE_ENDPOINT => 'geocode', |
|
| 26 | - GoogleMapsApiConfigFields::KEY => 'test_key' |
|
| 27 | - ]); |
|
| 28 | - $this->assertEquals($gm->getKey(), 'test_key'); |
|
| 29 | - $this->assertEquals($gm->getServiceEndpoint(), 'geocode'); |
|
| 30 | - } |
|
| 24 | + $gm = new GoogleMapsApi([ |
|
| 25 | + GoogleMapsApiConfigFields::SERVICE_ENDPOINT => 'geocode', |
|
| 26 | + GoogleMapsApiConfigFields::KEY => 'test_key' |
|
| 27 | + ]); |
|
| 28 | + $this->assertEquals($gm->getKey(), 'test_key'); |
|
| 29 | + $this->assertEquals($gm->getServiceEndpoint(), 'geocode'); |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -22,72 +22,72 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class GeometryTest extends TestCase { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var Geometry |
|
| 27 | - */ |
|
| 28 | - protected $geometry; |
|
| 25 | + /** |
|
| 26 | + * @var Geometry |
|
| 27 | + */ |
|
| 28 | + protected $geometry; |
|
| 29 | 29 | |
| 30 | - public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 30 | + public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 31 | 31 | |
| 32 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
| 32 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
| 33 | 33 | |
| 34 | - $this->geometry = new Geometry(); |
|
| 35 | - } |
|
| 34 | + $this->geometry = new Geometry(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @test |
|
| 39 | - */ |
|
| 40 | - public function testLocationSetterGetter() { |
|
| 37 | + /** |
|
| 38 | + * @test |
|
| 39 | + */ |
|
| 40 | + public function testLocationSetterGetter() { |
|
| 41 | 41 | |
| 42 | - $geometry = $this->geometry; |
|
| 42 | + $geometry = $this->geometry; |
|
| 43 | 43 | |
| 44 | - $geometry->setLocation(new Location([ |
|
| 45 | - LatLngFields::LAT => 20, |
|
| 46 | - LatLngFields::LNG => 33, |
|
| 47 | - ])); |
|
| 44 | + $geometry->setLocation(new Location([ |
|
| 45 | + LatLngFields::LAT => 20, |
|
| 46 | + LatLngFields::LNG => 33, |
|
| 47 | + ])); |
|
| 48 | 48 | |
| 49 | - $this->assertEquals(new Location([ |
|
| 50 | - LatLngFields::LAT => 20, |
|
| 51 | - LatLngFields::LNG => 33, |
|
| 52 | - ]), $geometry->getLocation()); |
|
| 49 | + $this->assertEquals(new Location([ |
|
| 50 | + LatLngFields::LAT => 20, |
|
| 51 | + LatLngFields::LNG => 33, |
|
| 52 | + ]), $geometry->getLocation()); |
|
| 53 | 53 | |
| 54 | - $this->assertEquals(20, $geometry->getLocation()->getLat()); |
|
| 55 | - $this->assertEquals(33, $geometry->getLocation()->getLng()); |
|
| 54 | + $this->assertEquals(20, $geometry->getLocation()->getLat()); |
|
| 55 | + $this->assertEquals(33, $geometry->getLocation()->getLng()); |
|
| 56 | 56 | |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @test |
|
| 61 | - */ |
|
| 62 | - public function testLocationSetterGetterViaArray() { |
|
| 59 | + /** |
|
| 60 | + * @test |
|
| 61 | + */ |
|
| 62 | + public function testLocationSetterGetterViaArray() { |
|
| 63 | 63 | |
| 64 | - $geometry = $this->geometry; |
|
| 64 | + $geometry = $this->geometry; |
|
| 65 | 65 | |
| 66 | - $geometry->setLocation([ |
|
| 67 | - LatLngFields::LAT => 20, |
|
| 68 | - LatLngFields::LNG => 33, |
|
| 69 | - ]); |
|
| 66 | + $geometry->setLocation([ |
|
| 67 | + LatLngFields::LAT => 20, |
|
| 68 | + LatLngFields::LNG => 33, |
|
| 69 | + ]); |
|
| 70 | 70 | |
| 71 | - $this->assertEquals(new Location([ |
|
| 72 | - LatLngFields::LAT => 20, |
|
| 73 | - LatLngFields::LNG => 33, |
|
| 74 | - ]), $geometry->getLocation()); |
|
| 71 | + $this->assertEquals(new Location([ |
|
| 72 | + LatLngFields::LAT => 20, |
|
| 73 | + LatLngFields::LNG => 33, |
|
| 74 | + ]), $geometry->getLocation()); |
|
| 75 | 75 | |
| 76 | - $this->assertEquals(20, $geometry->getLocation()->getLat()); |
|
| 77 | - $this->assertEquals(33, $geometry->getLocation()->getLng()); |
|
| 76 | + $this->assertEquals(20, $geometry->getLocation()->getLat()); |
|
| 77 | + $this->assertEquals(33, $geometry->getLocation()->getLng()); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @tets |
|
| 83 | - */ |
|
| 84 | - public function testLocationTypeSetterGetter() { |
|
| 81 | + /** |
|
| 82 | + * @tets |
|
| 83 | + */ |
|
| 84 | + public function testLocationTypeSetterGetter() { |
|
| 85 | 85 | |
| 86 | - $geometry = $this->geometry; |
|
| 86 | + $geometry = $this->geometry; |
|
| 87 | 87 | |
| 88 | - $geometry->setLocationType(GeometryLocationTypeValues::ROOFTOP); |
|
| 88 | + $geometry->setLocationType(GeometryLocationTypeValues::ROOFTOP); |
|
| 89 | 89 | |
| 90 | - $this->assertEquals(GeometryLocationTypeValues::ROOFTOP, $geometry->getLocationType()); |
|
| 90 | + $this->assertEquals(GeometryLocationTypeValues::ROOFTOP, $geometry->getLocationType()); |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -23,202 +23,202 @@ |
||
| 23 | 23 | |
| 24 | 24 | class GoogleMapsGeocodingTest extends TestCase { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var Geocoding |
|
| 28 | - */ |
|
| 29 | - protected $geocoding_no_key; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var Geocoding |
|
| 33 | - */ |
|
| 34 | - protected $geocoding_with_key; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var Geocoding |
|
| 38 | - */ |
|
| 39 | - protected $geocoding_with_sensor; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var Response |
|
| 43 | - */ |
|
| 44 | - protected $mock_response_ok; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var Response |
|
| 48 | - */ |
|
| 49 | - protected $mock_response_ko; |
|
| 50 | - |
|
| 51 | - public function setUp() { |
|
| 52 | - |
|
| 53 | - // This is the sample value from Google Maps official documentation |
|
| 54 | - $default_response_OK = [ |
|
| 55 | - 'results' => [ |
|
| 56 | - 0 => [ |
|
| 57 | - 'address_components' => [ |
|
| 58 | - 0 => [ |
|
| 59 | - 'long_name' => '277', |
|
| 60 | - 'short_name' => '277', |
|
| 61 | - 'types' => [ |
|
| 62 | - 0 => 'street_number', |
|
| 63 | - ], |
|
| 64 | - ], |
|
| 65 | - 1 => [ |
|
| 66 | - 'long_name' => 'Bedford Avenue', |
|
| 67 | - 'short_name' => 'Bedford Ave', |
|
| 68 | - 'types' => [ |
|
| 69 | - 0 => 'route', |
|
| 70 | - ], |
|
| 71 | - ], |
|
| 72 | - 2 => [ |
|
| 73 | - 'long_name' => 'Williamsburg', |
|
| 74 | - 'short_name' => 'Williamsburg', |
|
| 75 | - 'types' => [ |
|
| 76 | - 0 => 'neighborhood', |
|
| 77 | - 1 => 'political', |
|
| 78 | - ], |
|
| 79 | - ], |
|
| 80 | - 3 => [ |
|
| 81 | - 'long_name' => 'Brooklyn', |
|
| 82 | - 'short_name' => 'Brooklyn', |
|
| 83 | - 'types' => [ |
|
| 84 | - 0 => 'political', |
|
| 85 | - 1 => 'sublocality', |
|
| 86 | - 2 => 'sublocality_level_1', |
|
| 87 | - ], |
|
| 88 | - ], |
|
| 89 | - 4 => [ |
|
| 90 | - 'long_name' => 'Kings County', |
|
| 91 | - 'short_name' => 'Kings County', |
|
| 92 | - 'types' => [ |
|
| 93 | - 0 => 'administrative_area_level_2', |
|
| 94 | - 1 => 'political', |
|
| 95 | - ], |
|
| 96 | - ], |
|
| 97 | - 5 => [ |
|
| 98 | - 'long_name' => 'New York', |
|
| 99 | - 'short_name' => 'NY', |
|
| 100 | - 'types' => [ |
|
| 101 | - 0 => 'administrative_area_level_1', |
|
| 102 | - 1 => 'political', |
|
| 103 | - ], |
|
| 104 | - ], |
|
| 105 | - 6 => [ |
|
| 106 | - 'long_name' => 'United States', |
|
| 107 | - 'short_name' => 'US', |
|
| 108 | - 'types' => [ |
|
| 109 | - 0 => 'country', |
|
| 110 | - 1 => 'political', |
|
| 111 | - ], |
|
| 112 | - ], |
|
| 113 | - 7 => [ |
|
| 114 | - 'long_name' => '11211', |
|
| 115 | - 'short_name' => '11211', |
|
| 116 | - 'types' => [ |
|
| 117 | - 0 => 'postal_code', |
|
| 118 | - ], |
|
| 119 | - ], |
|
| 120 | - ], |
|
| 121 | - 'formatted_address' => '277 Bedford Ave, Brooklyn, NY 11211, USA', |
|
| 122 | - 'geometry' => [ |
|
| 123 | - 'location' => [ |
|
| 124 | - 'lat' => 40.71422050000000325553628499619662761688232421875, |
|
| 125 | - 'lng' => -73.961290300000001707303454168140888214111328125, |
|
| 126 | - ], |
|
| 127 | - 'location_type' => 'ROOFTOP', |
|
| 128 | - 'viewport' => [ |
|
| 129 | - 'northeast' => [ |
|
| 130 | - 'lat' => 40.7155694802914922547643072903156280517578125, |
|
| 131 | - 'lng' => -73.9599413197084913917933590710163116455078125, |
|
| 132 | - ], |
|
| 133 | - 'southwest' => [ |
|
| 134 | - 'lat' => 40.712871519708500045453547500073909759521484375, |
|
| 135 | - 'lng' => -73.9626392802914978119588340632617473602294921875, |
|
| 136 | - ], |
|
| 137 | - ], |
|
| 138 | - ], |
|
| 139 | - 'place_id' => 'ChIJd8BlQ2BZwokRAFUEcm_qrcA', |
|
| 140 | - 'types' => [ |
|
| 141 | - 0 => 'street_address', |
|
| 142 | - ], |
|
| 143 | - ], |
|
| 144 | - ], |
|
| 145 | - 'status' => 'OK', |
|
| 146 | - ]; |
|
| 147 | - |
|
| 148 | - $default_response_KO = array_merge($default_response_OK, [ |
|
| 149 | - 'status' => GoogleMapsResponseStatusValues::REQUEST_DENIED |
|
| 150 | - ]); |
|
| 151 | - |
|
| 152 | - // geocoding with API key |
|
| 153 | - // Remember to associate a valid payment method to your project |
|
| 154 | - $this->geocoding_with_key = new Geocoding([ |
|
| 155 | - GoogleMapsApiConfigFields::KEY => 'MyKey' |
|
| 156 | - ]); |
|
| 157 | - |
|
| 158 | - // geocoding with sensor |
|
| 159 | - $this->geocoding_with_sensor = new Geocoding([ |
|
| 160 | - GoogleMapsApiConfigFields::SENSOR => 'true' |
|
| 161 | - ]); |
|
| 162 | - |
|
| 163 | - // geocoding with NO API key |
|
| 164 | - $this->geocoding_no_key = new Geocoding(); |
|
| 165 | - |
|
| 166 | - $this->mock_response_ok = new Response(200, [], \GuzzleHttp\json_encode($default_response_OK)); |
|
| 167 | - $this->mock_response_ko = new Response(200, [], \GuzzleHttp\json_encode($default_response_KO)); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - public function testCheckGeocodingConfig() { |
|
| 171 | - |
|
| 172 | - $this->assertEquals(Geocoding::SERVICE_ENDPOINT, $this->geocoding_with_key->getGoogleMapsApi()->getServiceEndpoint()); |
|
| 173 | - $this->assertEquals('MyKey', $this->geocoding_with_key->getGoogleMapsApi()->getKey()); |
|
| 174 | - $this->assertEquals('', $this->geocoding_no_key->getGoogleMapsApi()->getKey()); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function testCheckGeocodingConfigWithSensor() { |
|
| 178 | - |
|
| 179 | - $this->assertEquals('true', $this->geocoding_with_sensor->getGoogleMapsApi()->getSensor()); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - public function testCheckGeocodingResponseOk() { |
|
| 183 | - |
|
| 184 | - $response = new GoogleMapsResponse($this->mock_response_ok); |
|
| 185 | - |
|
| 186 | - /** @var GeocodingResultsCollection $result */ |
|
| 187 | - $result = new GeocodingResultsCollection($response->getResults()); |
|
| 188 | - |
|
| 189 | - $this->assertNotNull($result); |
|
| 190 | - |
|
| 191 | - $array_result = $result->first()->toArray(); |
|
| 192 | - // Response array keys |
|
| 193 | - $this->assertArrayHasKey('address_components', $array_result); |
|
| 194 | - $this->assertArrayHasKey('geometry', $array_result); |
|
| 195 | - $this->assertArrayHasKey('place_id', $array_result); |
|
| 196 | - $this->assertArrayHasKey('formatted_address', $array_result); |
|
| 197 | - $this->assertArrayHasKey('types', $array_result); |
|
| 198 | - $this->assertArrayHasKey('location', $array_result['geometry']); |
|
| 199 | - |
|
| 200 | - $address = $result->first()->getAddress(); |
|
| 201 | - |
|
| 202 | - $this->assertEquals(8, $address->count()); |
|
| 203 | - |
|
| 204 | - $this->assertEquals(200, $response->getHttpStatusCode()); |
|
| 205 | - |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - public function testResponseKO() { |
|
| 209 | - |
|
| 210 | - $this->expectException(RequestException::class); |
|
| 211 | - new GoogleMapsResponse($this->mock_response_ko); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - public function testCamelToSnake() { |
|
| 215 | - |
|
| 216 | - $this->assertEquals('test_field_name', camel2Snake('testFieldName')); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public function testSnakeToCamel() { |
|
| 220 | - |
|
| 221 | - $this->assertEquals('testFieldName', snake2Camel('test_field_name')); |
|
| 222 | - } |
|
| 26 | + /** |
|
| 27 | + * @var Geocoding |
|
| 28 | + */ |
|
| 29 | + protected $geocoding_no_key; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var Geocoding |
|
| 33 | + */ |
|
| 34 | + protected $geocoding_with_key; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var Geocoding |
|
| 38 | + */ |
|
| 39 | + protected $geocoding_with_sensor; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var Response |
|
| 43 | + */ |
|
| 44 | + protected $mock_response_ok; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var Response |
|
| 48 | + */ |
|
| 49 | + protected $mock_response_ko; |
|
| 50 | + |
|
| 51 | + public function setUp() { |
|
| 52 | + |
|
| 53 | + // This is the sample value from Google Maps official documentation |
|
| 54 | + $default_response_OK = [ |
|
| 55 | + 'results' => [ |
|
| 56 | + 0 => [ |
|
| 57 | + 'address_components' => [ |
|
| 58 | + 0 => [ |
|
| 59 | + 'long_name' => '277', |
|
| 60 | + 'short_name' => '277', |
|
| 61 | + 'types' => [ |
|
| 62 | + 0 => 'street_number', |
|
| 63 | + ], |
|
| 64 | + ], |
|
| 65 | + 1 => [ |
|
| 66 | + 'long_name' => 'Bedford Avenue', |
|
| 67 | + 'short_name' => 'Bedford Ave', |
|
| 68 | + 'types' => [ |
|
| 69 | + 0 => 'route', |
|
| 70 | + ], |
|
| 71 | + ], |
|
| 72 | + 2 => [ |
|
| 73 | + 'long_name' => 'Williamsburg', |
|
| 74 | + 'short_name' => 'Williamsburg', |
|
| 75 | + 'types' => [ |
|
| 76 | + 0 => 'neighborhood', |
|
| 77 | + 1 => 'political', |
|
| 78 | + ], |
|
| 79 | + ], |
|
| 80 | + 3 => [ |
|
| 81 | + 'long_name' => 'Brooklyn', |
|
| 82 | + 'short_name' => 'Brooklyn', |
|
| 83 | + 'types' => [ |
|
| 84 | + 0 => 'political', |
|
| 85 | + 1 => 'sublocality', |
|
| 86 | + 2 => 'sublocality_level_1', |
|
| 87 | + ], |
|
| 88 | + ], |
|
| 89 | + 4 => [ |
|
| 90 | + 'long_name' => 'Kings County', |
|
| 91 | + 'short_name' => 'Kings County', |
|
| 92 | + 'types' => [ |
|
| 93 | + 0 => 'administrative_area_level_2', |
|
| 94 | + 1 => 'political', |
|
| 95 | + ], |
|
| 96 | + ], |
|
| 97 | + 5 => [ |
|
| 98 | + 'long_name' => 'New York', |
|
| 99 | + 'short_name' => 'NY', |
|
| 100 | + 'types' => [ |
|
| 101 | + 0 => 'administrative_area_level_1', |
|
| 102 | + 1 => 'political', |
|
| 103 | + ], |
|
| 104 | + ], |
|
| 105 | + 6 => [ |
|
| 106 | + 'long_name' => 'United States', |
|
| 107 | + 'short_name' => 'US', |
|
| 108 | + 'types' => [ |
|
| 109 | + 0 => 'country', |
|
| 110 | + 1 => 'political', |
|
| 111 | + ], |
|
| 112 | + ], |
|
| 113 | + 7 => [ |
|
| 114 | + 'long_name' => '11211', |
|
| 115 | + 'short_name' => '11211', |
|
| 116 | + 'types' => [ |
|
| 117 | + 0 => 'postal_code', |
|
| 118 | + ], |
|
| 119 | + ], |
|
| 120 | + ], |
|
| 121 | + 'formatted_address' => '277 Bedford Ave, Brooklyn, NY 11211, USA', |
|
| 122 | + 'geometry' => [ |
|
| 123 | + 'location' => [ |
|
| 124 | + 'lat' => 40.71422050000000325553628499619662761688232421875, |
|
| 125 | + 'lng' => -73.961290300000001707303454168140888214111328125, |
|
| 126 | + ], |
|
| 127 | + 'location_type' => 'ROOFTOP', |
|
| 128 | + 'viewport' => [ |
|
| 129 | + 'northeast' => [ |
|
| 130 | + 'lat' => 40.7155694802914922547643072903156280517578125, |
|
| 131 | + 'lng' => -73.9599413197084913917933590710163116455078125, |
|
| 132 | + ], |
|
| 133 | + 'southwest' => [ |
|
| 134 | + 'lat' => 40.712871519708500045453547500073909759521484375, |
|
| 135 | + 'lng' => -73.9626392802914978119588340632617473602294921875, |
|
| 136 | + ], |
|
| 137 | + ], |
|
| 138 | + ], |
|
| 139 | + 'place_id' => 'ChIJd8BlQ2BZwokRAFUEcm_qrcA', |
|
| 140 | + 'types' => [ |
|
| 141 | + 0 => 'street_address', |
|
| 142 | + ], |
|
| 143 | + ], |
|
| 144 | + ], |
|
| 145 | + 'status' => 'OK', |
|
| 146 | + ]; |
|
| 147 | + |
|
| 148 | + $default_response_KO = array_merge($default_response_OK, [ |
|
| 149 | + 'status' => GoogleMapsResponseStatusValues::REQUEST_DENIED |
|
| 150 | + ]); |
|
| 151 | + |
|
| 152 | + // geocoding with API key |
|
| 153 | + // Remember to associate a valid payment method to your project |
|
| 154 | + $this->geocoding_with_key = new Geocoding([ |
|
| 155 | + GoogleMapsApiConfigFields::KEY => 'MyKey' |
|
| 156 | + ]); |
|
| 157 | + |
|
| 158 | + // geocoding with sensor |
|
| 159 | + $this->geocoding_with_sensor = new Geocoding([ |
|
| 160 | + GoogleMapsApiConfigFields::SENSOR => 'true' |
|
| 161 | + ]); |
|
| 162 | + |
|
| 163 | + // geocoding with NO API key |
|
| 164 | + $this->geocoding_no_key = new Geocoding(); |
|
| 165 | + |
|
| 166 | + $this->mock_response_ok = new Response(200, [], \GuzzleHttp\json_encode($default_response_OK)); |
|
| 167 | + $this->mock_response_ko = new Response(200, [], \GuzzleHttp\json_encode($default_response_KO)); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + public function testCheckGeocodingConfig() { |
|
| 171 | + |
|
| 172 | + $this->assertEquals(Geocoding::SERVICE_ENDPOINT, $this->geocoding_with_key->getGoogleMapsApi()->getServiceEndpoint()); |
|
| 173 | + $this->assertEquals('MyKey', $this->geocoding_with_key->getGoogleMapsApi()->getKey()); |
|
| 174 | + $this->assertEquals('', $this->geocoding_no_key->getGoogleMapsApi()->getKey()); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function testCheckGeocodingConfigWithSensor() { |
|
| 178 | + |
|
| 179 | + $this->assertEquals('true', $this->geocoding_with_sensor->getGoogleMapsApi()->getSensor()); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + public function testCheckGeocodingResponseOk() { |
|
| 183 | + |
|
| 184 | + $response = new GoogleMapsResponse($this->mock_response_ok); |
|
| 185 | + |
|
| 186 | + /** @var GeocodingResultsCollection $result */ |
|
| 187 | + $result = new GeocodingResultsCollection($response->getResults()); |
|
| 188 | + |
|
| 189 | + $this->assertNotNull($result); |
|
| 190 | + |
|
| 191 | + $array_result = $result->first()->toArray(); |
|
| 192 | + // Response array keys |
|
| 193 | + $this->assertArrayHasKey('address_components', $array_result); |
|
| 194 | + $this->assertArrayHasKey('geometry', $array_result); |
|
| 195 | + $this->assertArrayHasKey('place_id', $array_result); |
|
| 196 | + $this->assertArrayHasKey('formatted_address', $array_result); |
|
| 197 | + $this->assertArrayHasKey('types', $array_result); |
|
| 198 | + $this->assertArrayHasKey('location', $array_result['geometry']); |
|
| 199 | + |
|
| 200 | + $address = $result->first()->getAddress(); |
|
| 201 | + |
|
| 202 | + $this->assertEquals(8, $address->count()); |
|
| 203 | + |
|
| 204 | + $this->assertEquals(200, $response->getHttpStatusCode()); |
|
| 205 | + |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + public function testResponseKO() { |
|
| 209 | + |
|
| 210 | + $this->expectException(RequestException::class); |
|
| 211 | + new GoogleMapsResponse($this->mock_response_ko); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + public function testCamelToSnake() { |
|
| 215 | + |
|
| 216 | + $this->assertEquals('test_field_name', camel2Snake('testFieldName')); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function testSnakeToCamel() { |
|
| 220 | + |
|
| 221 | + $this->assertEquals('testFieldName', snake2Camel('test_field_name')); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | } |
@@ -22,49 +22,49 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class LatLngBountTest extends TestCase { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var LatLngBounds |
|
| 27 | - */ |
|
| 28 | - private $lat_lng_bounds; |
|
| 25 | + /** |
|
| 26 | + * @var LatLngBounds |
|
| 27 | + */ |
|
| 28 | + private $lat_lng_bounds; |
|
| 29 | 29 | |
| 30 | - public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 30 | + public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 31 | 31 | |
| 32 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
| 32 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
| 33 | 33 | |
| 34 | - $this->lat_lng_bounds = new LatLngBounds(); |
|
| 35 | - } |
|
| 34 | + $this->lat_lng_bounds = new LatLngBounds(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @test |
|
| 39 | - */ |
|
| 40 | - public function testLatLngBoundSetterGetter() { |
|
| 37 | + /** |
|
| 38 | + * @test |
|
| 39 | + */ |
|
| 40 | + public function testLatLngBoundSetterGetter() { |
|
| 41 | 41 | |
| 42 | - $lat_lng_bounds = $this->lat_lng_bounds; |
|
| 42 | + $lat_lng_bounds = $this->lat_lng_bounds; |
|
| 43 | 43 | |
| 44 | - $southwest = new LatLng([ |
|
| 45 | - LatLngFields::LAT => 20.89, |
|
| 46 | - LatLngFields::LNG => -40.82, |
|
| 47 | - ]); |
|
| 44 | + $southwest = new LatLng([ |
|
| 45 | + LatLngFields::LAT => 20.89, |
|
| 46 | + LatLngFields::LNG => -40.82, |
|
| 47 | + ]); |
|
| 48 | 48 | |
| 49 | - $northeast = new LatLng([ |
|
| 50 | - LatLngFields::LAT => 22.73, |
|
| 51 | - LatLngFields::LNG => 3.6370, |
|
| 52 | - ]); |
|
| 49 | + $northeast = new LatLng([ |
|
| 50 | + LatLngFields::LAT => 22.73, |
|
| 51 | + LatLngFields::LNG => 3.6370, |
|
| 52 | + ]); |
|
| 53 | 53 | |
| 54 | - $lat_lng_bounds->setSouthwest($southwest); |
|
| 55 | - $lat_lng_bounds->setNortheast($northeast); |
|
| 54 | + $lat_lng_bounds->setSouthwest($southwest); |
|
| 55 | + $lat_lng_bounds->setNortheast($northeast); |
|
| 56 | 56 | |
| 57 | - $this->assertEquals(new LatLngBounds([ |
|
| 58 | - LatLngBoundsFields::SOUTHWEST => [ |
|
| 59 | - LatLngFields::LAT => 20.89, |
|
| 60 | - LatLngFields::LNG => -40.82, |
|
| 61 | - ], |
|
| 62 | - LatLngBoundsFields::NORTHEAST => [ |
|
| 63 | - LatLngFields::LAT => 22.73, |
|
| 64 | - LatLngFields::LNG => 3.6370, |
|
| 65 | - ], |
|
| 66 | - ]), $lat_lng_bounds); |
|
| 57 | + $this->assertEquals(new LatLngBounds([ |
|
| 58 | + LatLngBoundsFields::SOUTHWEST => [ |
|
| 59 | + LatLngFields::LAT => 20.89, |
|
| 60 | + LatLngFields::LNG => -40.82, |
|
| 61 | + ], |
|
| 62 | + LatLngBoundsFields::NORTHEAST => [ |
|
| 63 | + LatLngFields::LAT => 22.73, |
|
| 64 | + LatLngFields::LNG => 3.6370, |
|
| 65 | + ], |
|
| 66 | + ]), $lat_lng_bounds); |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -23,48 +23,48 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class ViewportTest extends TestCase { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var LatLngBounds |
|
| 28 | - */ |
|
| 29 | - private $viewport; |
|
| 26 | + /** |
|
| 27 | + * @var LatLngBounds |
|
| 28 | + */ |
|
| 29 | + private $viewport; |
|
| 30 | 30 | |
| 31 | - public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 31 | + public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 32 | 32 | |
| 33 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
| 33 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
| 34 | 34 | |
| 35 | - $this->viewport = new Viewport(); |
|
| 36 | - } |
|
| 35 | + $this->viewport = new Viewport(); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @test |
|
| 40 | - */ |
|
| 41 | - public function testViewportSetterGetter() { |
|
| 38 | + /** |
|
| 39 | + * @test |
|
| 40 | + */ |
|
| 41 | + public function testViewportSetterGetter() { |
|
| 42 | 42 | |
| 43 | - $viewport = $this->viewport; |
|
| 43 | + $viewport = $this->viewport; |
|
| 44 | 44 | |
| 45 | - $southwest = new LatLng([ |
|
| 46 | - LatLngFields::LAT => 20.89, |
|
| 47 | - LatLngFields::LNG => -40.82, |
|
| 48 | - ]); |
|
| 45 | + $southwest = new LatLng([ |
|
| 46 | + LatLngFields::LAT => 20.89, |
|
| 47 | + LatLngFields::LNG => -40.82, |
|
| 48 | + ]); |
|
| 49 | 49 | |
| 50 | - $northeast = new LatLng([ |
|
| 51 | - LatLngFields::LAT => 22.73, |
|
| 52 | - LatLngFields::LNG => 3.6370, |
|
| 53 | - ]); |
|
| 50 | + $northeast = new LatLng([ |
|
| 51 | + LatLngFields::LAT => 22.73, |
|
| 52 | + LatLngFields::LNG => 3.6370, |
|
| 53 | + ]); |
|
| 54 | 54 | |
| 55 | - $viewport->setSouthwest($southwest); |
|
| 56 | - $viewport->setNortheast($northeast); |
|
| 55 | + $viewport->setSouthwest($southwest); |
|
| 56 | + $viewport->setNortheast($northeast); |
|
| 57 | 57 | |
| 58 | - $this->assertEquals(new Viewport([ |
|
| 59 | - LatLngBoundsFields::SOUTHWEST => [ |
|
| 60 | - LatLngFields::LAT => 20.89, |
|
| 61 | - LatLngFields::LNG => -40.82, |
|
| 62 | - ], |
|
| 63 | - LatLngBoundsFields::NORTHEAST => [ |
|
| 64 | - LatLngFields::LAT => 22.73, |
|
| 65 | - LatLngFields::LNG => 3.6370, |
|
| 66 | - ], |
|
| 67 | - ]), $viewport); |
|
| 58 | + $this->assertEquals(new Viewport([ |
|
| 59 | + LatLngBoundsFields::SOUTHWEST => [ |
|
| 60 | + LatLngFields::LAT => 20.89, |
|
| 61 | + LatLngFields::LNG => -40.82, |
|
| 62 | + ], |
|
| 63 | + LatLngBoundsFields::NORTHEAST => [ |
|
| 64 | + LatLngFields::LAT => 22.73, |
|
| 65 | + LatLngFields::LNG => 3.6370, |
|
| 66 | + ], |
|
| 67 | + ]), $viewport); |
|
| 68 | 68 | |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -20,23 +20,23 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class LatLngTest extends TestCase { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @test |
|
| 25 | - */ |
|
| 26 | - public function testLatLngSetterGetter() { |
|
| 23 | + /** |
|
| 24 | + * @test |
|
| 25 | + */ |
|
| 26 | + public function testLatLngSetterGetter() { |
|
| 27 | 27 | |
| 28 | - $lat_lng = new LatLng(); |
|
| 28 | + $lat_lng = new LatLng(); |
|
| 29 | 29 | |
| 30 | - $lat_lng->setLat(-50.09); |
|
| 31 | - $lat_lng->setLng(-100); |
|
| 30 | + $lat_lng->setLat(-50.09); |
|
| 31 | + $lat_lng->setLng(-100); |
|
| 32 | 32 | |
| 33 | - $this->assertEquals(new LatLng([ |
|
| 34 | - LatLngFields::LAT => -50.09, |
|
| 35 | - LatLngFields::LNG => -100, |
|
| 36 | - ]), $lat_lng); |
|
| 33 | + $this->assertEquals(new LatLng([ |
|
| 34 | + LatLngFields::LAT => -50.09, |
|
| 35 | + LatLngFields::LNG => -100, |
|
| 36 | + ]), $lat_lng); |
|
| 37 | 37 | |
| 38 | - $this->assertEquals(-50.09, $lat_lng->getLat()); |
|
| 39 | - $this->assertEquals(-100, $lat_lng->getLng()); |
|
| 38 | + $this->assertEquals(-50.09, $lat_lng->getLat()); |
|
| 39 | + $this->assertEquals(-100, $lat_lng->getLng()); |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -20,23 +20,23 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class LocationTest extends TestCase { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @test |
|
| 25 | - */ |
|
| 26 | - public function testLocationSetterGetter() { |
|
| 23 | + /** |
|
| 24 | + * @test |
|
| 25 | + */ |
|
| 26 | + public function testLocationSetterGetter() { |
|
| 27 | 27 | |
| 28 | - $lat_lng = new Location(); |
|
| 28 | + $lat_lng = new Location(); |
|
| 29 | 29 | |
| 30 | - $lat_lng->setLat(-50.09); |
|
| 31 | - $lat_lng->setLng(-100); |
|
| 30 | + $lat_lng->setLat(-50.09); |
|
| 31 | + $lat_lng->setLng(-100); |
|
| 32 | 32 | |
| 33 | - $this->assertEquals(new Location([ |
|
| 34 | - LatLngFields::LAT => -50.09, |
|
| 35 | - LatLngFields::LNG => -100, |
|
| 36 | - ]), $lat_lng); |
|
| 33 | + $this->assertEquals(new Location([ |
|
| 34 | + LatLngFields::LAT => -50.09, |
|
| 35 | + LatLngFields::LNG => -100, |
|
| 36 | + ]), $lat_lng); |
|
| 37 | 37 | |
| 38 | - $this->assertEquals(-50.09, $lat_lng->getLat()); |
|
| 39 | - $this->assertEquals(-100, $lat_lng->getLng()); |
|
| 38 | + $this->assertEquals(-50.09, $lat_lng->getLat()); |
|
| 39 | + $this->assertEquals(-100, $lat_lng->getLng()); |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -21,87 +21,87 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class AddressComponentTest extends TestCase { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var AddressComponent |
|
| 26 | - */ |
|
| 27 | - private $address_component_1; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var AddressComponent |
|
| 31 | - */ |
|
| 32 | - private $address_component_2; |
|
| 33 | - |
|
| 34 | - public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 35 | - |
|
| 36 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
| 37 | - |
|
| 38 | - $this->address_component_1 = new AddressComponent([ |
|
| 39 | - AddressComponentFields::LONG_NAME => 'Location Long name', |
|
| 40 | - AddressComponentFields::SHORT_NAME => 'Location Short name', |
|
| 41 | - AddressComponentFields::TYPES => [ |
|
| 42 | - 'type 1', |
|
| 43 | - 'type 2', |
|
| 44 | - ] |
|
| 45 | - ]); |
|
| 46 | - |
|
| 47 | - $this->address_component_2 = new AddressComponent([ |
|
| 48 | - AddressComponentFields::LONG_NAME => 'Location Long name (second)', |
|
| 49 | - AddressComponentFields::SHORT_NAME => 'Location Short name (second)', |
|
| 50 | - AddressComponentFields::TYPES => [ |
|
| 51 | - 'type 3', |
|
| 52 | - 'type 4', |
|
| 53 | - ] |
|
| 54 | - ]); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @test |
|
| 59 | - */ |
|
| 60 | - public function testAddressComponentInit() { |
|
| 61 | - |
|
| 62 | - $address_component = $this->address_component_1; |
|
| 63 | - |
|
| 64 | - $this->assertEquals('Location Long name', $address_component->getLongName()); |
|
| 65 | - $this->assertEquals('Location Short name', $address_component->getShortName()); |
|
| 66 | - $this->assertEquals([ |
|
| 67 | - 'type 1', |
|
| 68 | - 'type 2', |
|
| 69 | - ], $address_component->getTypes()); |
|
| 70 | - |
|
| 71 | - $this->assertEquals(2, count($address_component->getTypes())); |
|
| 72 | - $this->assertArrayNotHasKey(3, $address_component->getTypes()); |
|
| 73 | - |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @test |
|
| 78 | - */ |
|
| 79 | - public function testAddressItems() { |
|
| 80 | - |
|
| 81 | - $address = new Address(); |
|
| 82 | - |
|
| 83 | - $address->addItem($this->address_component_1); |
|
| 84 | - $address->addItem($this->address_component_2); |
|
| 85 | - |
|
| 86 | - $this->assertEquals(2, $address->count()); |
|
| 87 | - $this->assertEquals($this->address_component_1, $address->first()); |
|
| 88 | - $this->assertEquals($this->address_component_2, $address->last()); |
|
| 89 | - $this->assertEquals(1, $address->getLastIndex()); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @test |
|
| 94 | - */ |
|
| 95 | - public function testAddressIndex() { |
|
| 96 | - |
|
| 97 | - $address = new Address(); |
|
| 98 | - |
|
| 99 | - $address->addItem($this->address_component_1); |
|
| 100 | - $address->addItem($this->address_component_2); |
|
| 101 | - |
|
| 102 | - $this->assertEquals($this->address_component_1, $address->current()); |
|
| 103 | - |
|
| 104 | - $address->seek(1); |
|
| 105 | - $this->assertEquals($this->address_component_2, $address->current()); |
|
| 106 | - } |
|
| 24 | + /** |
|
| 25 | + * @var AddressComponent |
|
| 26 | + */ |
|
| 27 | + private $address_component_1; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var AddressComponent |
|
| 31 | + */ |
|
| 32 | + private $address_component_2; |
|
| 33 | + |
|
| 34 | + public function setUp()/* The :void return type declaration that should be here would cause a BC issue */ { |
|
| 35 | + |
|
| 36 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
| 37 | + |
|
| 38 | + $this->address_component_1 = new AddressComponent([ |
|
| 39 | + AddressComponentFields::LONG_NAME => 'Location Long name', |
|
| 40 | + AddressComponentFields::SHORT_NAME => 'Location Short name', |
|
| 41 | + AddressComponentFields::TYPES => [ |
|
| 42 | + 'type 1', |
|
| 43 | + 'type 2', |
|
| 44 | + ] |
|
| 45 | + ]); |
|
| 46 | + |
|
| 47 | + $this->address_component_2 = new AddressComponent([ |
|
| 48 | + AddressComponentFields::LONG_NAME => 'Location Long name (second)', |
|
| 49 | + AddressComponentFields::SHORT_NAME => 'Location Short name (second)', |
|
| 50 | + AddressComponentFields::TYPES => [ |
|
| 51 | + 'type 3', |
|
| 52 | + 'type 4', |
|
| 53 | + ] |
|
| 54 | + ]); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @test |
|
| 59 | + */ |
|
| 60 | + public function testAddressComponentInit() { |
|
| 61 | + |
|
| 62 | + $address_component = $this->address_component_1; |
|
| 63 | + |
|
| 64 | + $this->assertEquals('Location Long name', $address_component->getLongName()); |
|
| 65 | + $this->assertEquals('Location Short name', $address_component->getShortName()); |
|
| 66 | + $this->assertEquals([ |
|
| 67 | + 'type 1', |
|
| 68 | + 'type 2', |
|
| 69 | + ], $address_component->getTypes()); |
|
| 70 | + |
|
| 71 | + $this->assertEquals(2, count($address_component->getTypes())); |
|
| 72 | + $this->assertArrayNotHasKey(3, $address_component->getTypes()); |
|
| 73 | + |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @test |
|
| 78 | + */ |
|
| 79 | + public function testAddressItems() { |
|
| 80 | + |
|
| 81 | + $address = new Address(); |
|
| 82 | + |
|
| 83 | + $address->addItem($this->address_component_1); |
|
| 84 | + $address->addItem($this->address_component_2); |
|
| 85 | + |
|
| 86 | + $this->assertEquals(2, $address->count()); |
|
| 87 | + $this->assertEquals($this->address_component_1, $address->first()); |
|
| 88 | + $this->assertEquals($this->address_component_2, $address->last()); |
|
| 89 | + $this->assertEquals(1, $address->getLastIndex()); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @test |
|
| 94 | + */ |
|
| 95 | + public function testAddressIndex() { |
|
| 96 | + |
|
| 97 | + $address = new Address(); |
|
| 98 | + |
|
| 99 | + $address->addItem($this->address_component_1); |
|
| 100 | + $address->addItem($this->address_component_2); |
|
| 101 | + |
|
| 102 | + $this->assertEquals($this->address_component_1, $address->current()); |
|
| 103 | + |
|
| 104 | + $address->seek(1); |
|
| 105 | + $this->assertEquals($this->address_component_2, $address->current()); |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -19,27 +19,27 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class AddressComponent extends AbstractObject { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $long_name = null; |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $long_name = null; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $short_name = null; |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $short_name = null; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $types = null; |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $types = null; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $typeCheck = [ |
|
| 41 | - AddressComponentFields::LONG_NAME => 'string', |
|
| 42 | - AddressComponentFields::SHORT_NAME => 'string', |
|
| 43 | - AddressComponentFields::TYPES => 'array' |
|
| 44 | - ]; |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $typeCheck = [ |
|
| 41 | + AddressComponentFields::LONG_NAME => 'string', |
|
| 42 | + AddressComponentFields::SHORT_NAME => 'string', |
|
| 43 | + AddressComponentFields::TYPES => 'array' |
|
| 44 | + ]; |
|
| 45 | 45 | } |
| 46 | 46 | \ No newline at end of file |