Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like AbstractIvoryGoogleMapExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractIvoryGoogleMapExtensionTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | abstract class AbstractIvoryGoogleMapExtensionTest extends \PHPUnit_Framework_TestCase |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * @var ContainerBuilder |
||
| 37 | */ |
||
| 38 | private $container; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var bool |
||
| 42 | */ |
||
| 43 | private $debug; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $locale; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var HttpClient|\PHPUnit_Framework_MockObject_MockObject |
||
| 52 | */ |
||
| 53 | private $client; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var MessageFactory|\PHPUnit_Framework_MockObject_MockObject |
||
| 57 | */ |
||
| 58 | private $messageFactory; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | protected function setUp() |
||
| 64 | { |
||
| 65 | $this->container = new ContainerBuilder(); |
||
| 66 | $this->container->setParameter('kernel.debug', $this->debug = false); |
||
| 67 | $this->container->setParameter('locale', $this->locale = 'en'); |
||
| 68 | $this->container->set('httplug.client', $this->client = $this->createClientMock()); |
||
| 69 | $this->container->set('httplug.message_factory', $this->messageFactory = $this->createMessageFactoryMock()); |
||
| 70 | $this->container->registerExtension($extension = new IvoryGoogleMapExtension()); |
||
| 71 | $this->container->loadFromExtension($extension->getAlias()); |
||
| 72 | (new IvoryGoogleMapBundle())->build($this->container); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param ContainerBuilder $container |
||
| 77 | * @param string $configuration |
||
| 78 | */ |
||
| 79 | abstract protected function loadConfiguration(ContainerBuilder $container, $configuration); |
||
| 80 | |||
| 81 | public function testDefaultState() |
||
| 82 | { |
||
| 83 | $this->container->compile(); |
||
| 84 | |||
| 85 | $apiHelper = $this->container->get('ivory.google_map.helper.api'); |
||
| 86 | $mapHelper = $this->container->get('ivory.google_map.helper.map'); |
||
| 87 | $placeAutocompleteHelper = $this->container->get('ivory.google_map.helper.place_autocomplete'); |
||
| 88 | |||
| 89 | $this->assertInstanceOf(ApiHelper::class, $apiHelper); |
||
| 90 | $this->assertInstanceOf(MapHelper::class, $mapHelper); |
||
| 91 | $this->assertInstanceOf(PlaceAutocompleteHelper::class, $placeAutocompleteHelper); |
||
| 92 | |||
| 93 | $formatter = $this->container->get('ivory.google_map.helper.formatter'); |
||
| 94 | $loaderRenderer = $this->container->get('ivory.google_map.helper.renderer.loader');; |
||
| 95 | |||
| 96 | $this->assertSame($this->debug, $formatter->isDebug()); |
||
| 97 | $this->assertSame($this->locale, $loaderRenderer->getLanguage()); |
||
| 98 | $this->assertFalse($loaderRenderer->hasKey()); |
||
| 99 | |||
| 100 | $this->assertTrue($this->container->get('ivory.google_map.helper.renderer.control.manager')->hasRenderers()); |
||
| 101 | $this->assertTrue($this->container->get('ivory.google_map.helper.renderer.overlay.extendable')->hasRenderers()); |
||
| 102 | $this->assertTrue($this->container->get('ivory.google_map.helper.event_dispatcher')->hasListeners()); |
||
| 103 | |||
| 104 | $this->assertFalse($this->container->has('ivory.google_map.direction')); |
||
| 105 | $this->assertFalse($this->container->has('ivory.google_map.distance_matrix')); |
||
| 106 | $this->assertFalse($this->container->has('ivory.google_map.elevation')); |
||
| 107 | $this->assertFalse($this->container->has('ivory.google_map.geocoder')); |
||
| 108 | $this->assertFalse($this->container->has('ivory.google_map.time_zone')); |
||
| 109 | |||
| 110 | $this->assertFalse($this->container->has('ivory.google_map.templating.api')); |
||
| 111 | $this->assertFalse($this->container->has('ivory.google_map.templating.map')); |
||
| 112 | $this->assertFalse($this->container->has('ivory.google_map.templating.place_autocomplete')); |
||
| 113 | |||
| 114 | $this->assertFalse($this->container->has('ivory.google_map.twig.extension.api')); |
||
| 115 | $this->assertFalse($this->container->has('ivory.google_map.twig.extension.map')); |
||
| 116 | $this->assertFalse($this->container->has('ivory.google_map.twig.extension.place_autocomplete')); |
||
| 117 | } |
||
| 118 | |||
| 119 | public function testTemplatingHelpers() |
||
| 120 | { |
||
| 121 | $this->container->setDefinition('templating.engine.php', new Definition(\stdClass::class)); |
||
| 122 | $this->container->compile(); |
||
| 123 | |||
| 124 | $this->assertTrue($this->container->has('ivory.google_map.templating.api')); |
||
| 125 | $this->assertTrue($this->container->has('ivory.google_map.templating.map')); |
||
| 126 | $this->assertTrue($this->container->has('ivory.google_map.templating.place_autocomplete')); |
||
| 127 | } |
||
| 128 | |||
| 129 | public function testTwigExtensions() |
||
| 130 | { |
||
| 131 | $this->container->setDefinition('twig', new Definition(\stdClass::class)); |
||
| 132 | $this->container->compile(); |
||
| 133 | |||
| 134 | $this->assertTrue($this->container->has('ivory.google_map.twig.extension.api')); |
||
| 135 | $this->assertTrue($this->container->has('ivory.google_map.twig.extension.map')); |
||
| 136 | $this->assertTrue($this->container->has('ivory.google_map.twig.extension.place_autocomplete')); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function testTemplatingFormResources() |
||
| 140 | { |
||
| 141 | $this->container->setParameter($parameter = 'templating.helper.form.resources', $resources = ['resource']); |
||
| 142 | $this->container->compile(); |
||
| 143 | |||
| 144 | $this->assertSame( |
||
| 145 | array_merge(['IvoryGoogleMapBundle:Form'], $resources), |
||
| 146 | $this->container->getParameter($parameter) |
||
| 147 | ); |
||
| 148 | } |
||
| 149 | |||
| 150 | public function testTwigFormResources() |
||
| 151 | { |
||
| 152 | $this->container->setParameter($parameter = 'twig.form.resources', $resources = ['resource']); |
||
| 153 | $this->container->compile(); |
||
| 154 | |||
| 155 | $this->assertSame( |
||
| 156 | array_merge(['IvoryGoogleMapBundle:Form:place_autocomplete_widget.html.twig'], $resources), |
||
| 157 | $this->container->getParameter($parameter) |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | |||
| 161 | public function testFormatterDebug() |
||
| 162 | { |
||
| 163 | $this->loadConfiguration($this->container, 'debug'); |
||
| 164 | $this->container->compile(); |
||
| 165 | |||
| 166 | $this->assertTrue($this->container->get('ivory.google_map.helper.formatter')->isDebug()); |
||
| 167 | } |
||
| 168 | |||
| 169 | public function testMapLanguage() |
||
| 170 | { |
||
| 171 | $this->loadConfiguration($this->container, 'language'); |
||
| 172 | $this->container->compile(); |
||
| 173 | |||
| 174 | $this->assertSame('fr', $this->container->get('ivory.google_map.helper.renderer.loader')->getLanguage()); |
||
| 175 | } |
||
| 176 | |||
| 177 | public function testMapApiKey() |
||
| 178 | { |
||
| 179 | $this->loadConfiguration($this->container, 'api_key'); |
||
| 180 | $this->container->compile(); |
||
| 181 | |||
| 182 | $this->assertSame('key', $this->container->get('ivory.google_map.helper.renderer.loader')->getKey()); |
||
| 183 | } |
||
| 184 | |||
| 185 | public function testDirection() |
||
| 186 | { |
||
| 187 | $this->loadConfiguration($this->container, 'direction'); |
||
| 188 | $this->container->compile(); |
||
| 189 | |||
| 190 | $direction = $this->container->get('ivory.google_map.direction'); |
||
| 191 | |||
| 192 | $this->assertInstanceOf(DirectionService::class, $direction); |
||
| 193 | $this->assertSame($this->client, $direction->getClient()); |
||
| 194 | $this->assertSame($this->messageFactory, $direction->getMessageFactory()); |
||
| 195 | $this->assertTrue($direction->isHttps()); |
||
| 196 | $this->assertSame(DirectionService::FORMAT_JSON, $direction->getFormat()); |
||
| 197 | $this->assertFalse($direction->hasBusinessAccount()); |
||
| 198 | } |
||
| 199 | |||
| 200 | public function testDirectionHttps() |
||
| 201 | { |
||
| 202 | $this->loadConfiguration($this->container, 'direction_https'); |
||
| 203 | $this->container->compile(); |
||
| 204 | |||
| 205 | $this->assertFalse($this->container->get('ivory.google_map.direction')->isHttps()); |
||
| 206 | } |
||
| 207 | |||
| 208 | public function testDirectionFormat() |
||
| 209 | { |
||
| 210 | $this->loadConfiguration($this->container, 'direction_format'); |
||
| 211 | $this->container->compile(); |
||
| 212 | |||
| 213 | $this->assertSame(DirectionService::FORMAT_XML, $this->container->get('ivory.google_map.direction')->getFormat()); |
||
| 214 | } |
||
| 215 | |||
| 216 | public function testDirectionApiKey() |
||
| 217 | { |
||
| 218 | $this->loadConfiguration($this->container, 'direction_api_key'); |
||
| 219 | $this->container->compile(); |
||
| 220 | |||
| 221 | $this->assertSame('key', $this->container->get('ivory.google_map.direction')->getKey()); |
||
| 222 | } |
||
| 223 | |||
| 224 | public function testDirectionBusinessAccount() |
||
| 225 | { |
||
| 226 | $this->loadConfiguration($this->container, 'direction_business_account'); |
||
| 227 | $this->container->compile(); |
||
| 228 | |||
| 229 | $direction = $this->container->get('ivory.google_map.direction'); |
||
| 230 | |||
| 231 | $this->assertTrue($direction->hasBusinessAccount()); |
||
| 232 | $this->assertSame('my-client', $direction->getBusinessAccount()->getClientId()); |
||
| 233 | $this->assertSame('my-secret', $direction->getBusinessAccount()->getSecret()); |
||
| 234 | $this->assertFalse($direction->getBusinessAccount()->hasChannel()); |
||
| 235 | } |
||
| 236 | |||
| 237 | public function testDirectionBusinessAccountChannel() |
||
| 238 | { |
||
| 239 | $this->loadConfiguration($this->container, 'direction_business_account_channel'); |
||
| 240 | $this->container->compile(); |
||
| 241 | |||
| 242 | $direction = $this->container->get('ivory.google_map.direction'); |
||
| 243 | |||
| 244 | $this->assertTrue($direction->hasBusinessAccount()); |
||
| 245 | $this->assertSame('my-client', $direction->getBusinessAccount()->getClientId()); |
||
| 246 | $this->assertSame('my-secret', $direction->getBusinessAccount()->getSecret()); |
||
| 247 | $this->assertSame('my-channel', $direction->getBusinessAccount()->getChannel()); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 252 | */ |
||
| 253 | public function testDirectionBusinessAccountInvalid() |
||
| 254 | { |
||
| 255 | $this->loadConfiguration($this->container, 'direction_business_account_invalid'); |
||
| 256 | $this->container->compile(); |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 261 | */ |
||
| 262 | public function testDirectionInvalid() |
||
| 263 | { |
||
| 264 | $this->loadConfiguration($this->container, 'direction_invalid'); |
||
| 265 | $this->container->compile(); |
||
| 266 | } |
||
| 267 | |||
| 268 | public function testDistanceMatrix() |
||
| 269 | { |
||
| 270 | $this->loadConfiguration($this->container, 'distance_matrix'); |
||
| 271 | $this->container->compile(); |
||
| 272 | |||
| 273 | $distanceMatrix = $this->container->get('ivory.google_map.distance_matrix'); |
||
| 274 | |||
| 275 | $this->assertInstanceOf(DistanceMatrixService::class, $distanceMatrix); |
||
| 276 | $this->assertSame($this->client, $distanceMatrix->getClient()); |
||
| 277 | $this->assertSame($this->messageFactory, $distanceMatrix->getMessageFactory()); |
||
| 278 | $this->assertTrue($distanceMatrix->isHttps()); |
||
| 279 | $this->assertSame(DistanceMatrixService::FORMAT_JSON, $distanceMatrix->getFormat()); |
||
| 280 | $this->assertFalse($distanceMatrix->hasBusinessAccount()); |
||
| 281 | } |
||
| 282 | |||
| 283 | public function testDistanceMatrixHttps() |
||
| 284 | { |
||
| 285 | $this->loadConfiguration($this->container, 'distance_matrix_https'); |
||
| 286 | $this->container->compile(); |
||
| 287 | |||
| 288 | $this->assertFalse($this->container->get('ivory.google_map.distance_matrix')->isHttps()); |
||
| 289 | } |
||
| 290 | |||
| 291 | public function testDistanceMatrixFormat() |
||
| 292 | { |
||
| 293 | $this->loadConfiguration($this->container, 'distance_matrix_format'); |
||
| 294 | $this->container->compile(); |
||
| 295 | |||
| 296 | $this->assertSame( |
||
| 297 | DistanceMatrixService::FORMAT_XML, |
||
| 298 | $this->container->get('ivory.google_map.distance_matrix')->getFormat() |
||
| 299 | ); |
||
| 300 | } |
||
| 301 | |||
| 302 | public function testDistanceMatrixApiKey() |
||
| 303 | { |
||
| 304 | $this->loadConfiguration($this->container, 'distance_matrix_api_key'); |
||
| 305 | $this->container->compile(); |
||
| 306 | |||
| 307 | $this->assertSame('key', $this->container->get('ivory.google_map.distance_matrix')->getKey()); |
||
| 308 | } |
||
| 309 | |||
| 310 | public function testDistanceMatrixBusinessAccount() |
||
| 311 | { |
||
| 312 | $this->loadConfiguration($this->container, 'distance_matrix_business_account'); |
||
| 313 | $this->container->compile(); |
||
| 314 | |||
| 315 | $distanceMatrix = $this->container->get('ivory.google_map.distance_matrix'); |
||
| 316 | |||
| 317 | $this->assertTrue($distanceMatrix->hasBusinessAccount()); |
||
| 318 | $this->assertSame('my-client', $distanceMatrix->getBusinessAccount()->getClientId()); |
||
| 319 | $this->assertSame('my-secret', $distanceMatrix->getBusinessAccount()->getSecret()); |
||
| 320 | $this->assertFalse($distanceMatrix->getBusinessAccount()->hasChannel()); |
||
| 321 | } |
||
| 322 | |||
| 323 | public function testDistanceMatrixBusinessAccountChannel() |
||
| 324 | { |
||
| 325 | $this->loadConfiguration($this->container, 'distance_matrix_business_account_channel'); |
||
| 326 | $this->container->compile(); |
||
| 327 | |||
| 328 | $distanceMatrix = $this->container->get('ivory.google_map.distance_matrix'); |
||
| 329 | |||
| 330 | $this->assertTrue($distanceMatrix->hasBusinessAccount()); |
||
| 331 | $this->assertSame('my-client', $distanceMatrix->getBusinessAccount()->getClientId()); |
||
| 332 | $this->assertSame('my-secret', $distanceMatrix->getBusinessAccount()->getSecret()); |
||
| 333 | $this->assertSame('my-channel', $distanceMatrix->getBusinessAccount()->getChannel()); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 338 | */ |
||
| 339 | public function testDistanceMatrixBusinessAccountInvalid() |
||
| 340 | { |
||
| 341 | $this->loadConfiguration($this->container, 'distance_matrix_business_account_invalid'); |
||
| 342 | $this->container->compile(); |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 347 | */ |
||
| 348 | public function testDistanceMatrixInvalid() |
||
| 349 | { |
||
| 350 | $this->loadConfiguration($this->container, 'distance_matrix_invalid'); |
||
| 351 | $this->container->compile(); |
||
| 352 | } |
||
| 353 | |||
| 354 | public function testElevation() |
||
| 355 | { |
||
| 356 | $this->loadConfiguration($this->container, 'elevation'); |
||
| 357 | $this->container->compile(); |
||
| 358 | |||
| 359 | $elevation = $this->container->get('ivory.google_map.elevation'); |
||
| 360 | |||
| 361 | $this->assertInstanceOf(ElevationService::class, $elevation); |
||
| 362 | $this->assertSame($this->client, $elevation->getClient()); |
||
| 363 | $this->assertSame($this->messageFactory, $elevation->getMessageFactory()); |
||
| 364 | $this->assertTrue($elevation->isHttps()); |
||
| 365 | $this->assertSame(ElevationService::FORMAT_JSON, $elevation->getFormat()); |
||
| 366 | $this->assertFalse($elevation->hasBusinessAccount()); |
||
| 367 | } |
||
| 368 | |||
| 369 | public function testElevationHttps() |
||
| 370 | { |
||
| 371 | $this->loadConfiguration($this->container, 'elevation_https'); |
||
| 372 | $this->container->compile(); |
||
| 373 | |||
| 374 | $this->assertFalse($this->container->get('ivory.google_map.elevation')->isHttps()); |
||
| 375 | } |
||
| 376 | |||
| 377 | public function testElevationFormat() |
||
| 378 | { |
||
| 379 | $this->loadConfiguration($this->container, 'elevation_format'); |
||
| 380 | $this->container->compile(); |
||
| 381 | |||
| 382 | $this->assertSame(ElevationService::FORMAT_XML, $this->container->get('ivory.google_map.elevation')->getFormat()); |
||
| 383 | } |
||
| 384 | |||
| 385 | public function testElevationApiKey() |
||
| 386 | { |
||
| 387 | $this->loadConfiguration($this->container, 'elevation_api_key'); |
||
| 388 | $this->container->compile(); |
||
| 389 | |||
| 390 | $this->assertSame('key', $this->container->get('ivory.google_map.elevation')->getKey()); |
||
| 391 | } |
||
| 392 | |||
| 393 | public function testElevationBusinessAccount() |
||
| 394 | { |
||
| 395 | $this->loadConfiguration($this->container, 'elevation_business_account'); |
||
| 396 | $this->container->compile(); |
||
| 397 | |||
| 398 | $elevation = $this->container->get('ivory.google_map.elevation'); |
||
| 399 | |||
| 400 | $this->assertTrue($elevation->hasBusinessAccount()); |
||
| 401 | $this->assertSame('my-client', $elevation->getBusinessAccount()->getClientId()); |
||
| 402 | $this->assertSame('my-secret', $elevation->getBusinessAccount()->getSecret()); |
||
| 403 | $this->assertFalse($elevation->getBusinessAccount()->hasChannel()); |
||
| 404 | } |
||
| 405 | |||
| 406 | public function testElevationBusinessAccountChannel() |
||
| 407 | { |
||
| 408 | $this->loadConfiguration($this->container, 'elevation_business_account_channel'); |
||
| 409 | $this->container->compile(); |
||
| 410 | |||
| 411 | $elevation = $this->container->get('ivory.google_map.elevation'); |
||
| 412 | |||
| 413 | $this->assertTrue($elevation->hasBusinessAccount()); |
||
| 414 | $this->assertSame('my-client', $elevation->getBusinessAccount()->getClientId()); |
||
| 415 | $this->assertSame('my-secret', $elevation->getBusinessAccount()->getSecret()); |
||
| 416 | $this->assertSame('my-channel', $elevation->getBusinessAccount()->getChannel()); |
||
| 417 | } |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 421 | */ |
||
| 422 | public function testElevationBusinessAccountInvalid() |
||
| 423 | { |
||
| 424 | $this->loadConfiguration($this->container, 'elevation_business_account_invalid'); |
||
| 425 | $this->container->compile(); |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 430 | */ |
||
| 431 | public function testElevationInvalid() |
||
| 432 | { |
||
| 433 | $this->loadConfiguration($this->container, 'elevation_invalid'); |
||
| 434 | $this->container->compile(); |
||
| 435 | } |
||
| 436 | |||
| 437 | public function testGeocoder() |
||
| 438 | { |
||
| 439 | $this->loadConfiguration($this->container, 'geocoder'); |
||
| 440 | $this->container->compile(); |
||
| 441 | |||
| 442 | $geocoder = $this->container->get('ivory.google_map.geocoder'); |
||
| 443 | |||
| 444 | $this->assertInstanceOf(GeocoderService::class, $geocoder); |
||
| 445 | $this->assertSame($this->client, $geocoder->getClient()); |
||
| 446 | $this->assertSame($this->messageFactory, $geocoder->getMessageFactory()); |
||
| 447 | $this->assertTrue($geocoder->isHttps()); |
||
| 448 | $this->assertSame(GeocoderService::FORMAT_JSON, $geocoder->getFormat()); |
||
| 449 | $this->assertFalse($geocoder->hasBusinessAccount()); |
||
| 450 | } |
||
| 451 | |||
| 452 | public function testGeocoderHttps() |
||
| 453 | { |
||
| 454 | $this->loadConfiguration($this->container, 'geocoder_https'); |
||
| 455 | $this->container->compile(); |
||
| 456 | |||
| 457 | $this->assertFalse($this->container->get('ivory.google_map.geocoder')->isHttps()); |
||
| 458 | } |
||
| 459 | |||
| 460 | public function testGeocoderFormat() |
||
| 461 | { |
||
| 462 | $this->loadConfiguration($this->container, 'geocoder_format'); |
||
| 463 | $this->container->compile(); |
||
| 464 | |||
| 465 | $this->assertSame( |
||
| 466 | GeocoderService::FORMAT_XML, |
||
| 467 | $this->container->get('ivory.google_map.geocoder')->getFormat() |
||
| 468 | ); |
||
| 469 | } |
||
| 470 | |||
| 471 | public function testGeocoderApiKey() |
||
| 472 | { |
||
| 473 | $this->loadConfiguration($this->container, 'geocoder_api_key'); |
||
| 474 | $this->container->compile(); |
||
| 475 | |||
| 476 | $this->assertSame('key', $this->container->get('ivory.google_map.geocoder')->getKey()); |
||
| 477 | } |
||
| 478 | |||
| 479 | public function testGeocoderBusinessAccount() |
||
| 480 | { |
||
| 481 | $this->loadConfiguration($this->container, 'geocoder_business_account'); |
||
| 482 | $this->container->compile(); |
||
| 483 | |||
| 484 | $geocoder = $this->container->get('ivory.google_map.geocoder'); |
||
| 485 | |||
| 486 | $this->assertTrue($geocoder->hasBusinessAccount()); |
||
| 487 | $this->assertSame('my-client', $geocoder->getBusinessAccount()->getClientId()); |
||
| 488 | $this->assertSame('my-secret', $geocoder->getBusinessAccount()->getSecret()); |
||
| 489 | $this->assertFalse($geocoder->getBusinessAccount()->hasChannel()); |
||
| 490 | } |
||
| 491 | |||
| 492 | public function testGeocoderBusinessAccountChannel() |
||
| 493 | { |
||
| 494 | $this->loadConfiguration($this->container, 'geocoder_business_account_channel'); |
||
| 495 | $this->container->compile(); |
||
| 496 | |||
| 497 | $geocoder = $this->container->get('ivory.google_map.geocoder'); |
||
| 498 | |||
| 499 | $this->assertTrue($geocoder->hasBusinessAccount()); |
||
| 500 | $this->assertSame('my-client', $geocoder->getBusinessAccount()->getClientId()); |
||
| 501 | $this->assertSame('my-secret', $geocoder->getBusinessAccount()->getSecret()); |
||
| 502 | $this->assertSame('my-channel', $geocoder->getBusinessAccount()->getChannel()); |
||
| 503 | } |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 507 | */ |
||
| 508 | public function testGeocoderBusinessAccountInvalid() |
||
| 509 | { |
||
| 510 | $this->loadConfiguration($this->container, 'geocoder_business_account_invalid'); |
||
| 511 | $this->container->compile(); |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 516 | */ |
||
| 517 | public function testGeocoderInvalid() |
||
| 518 | { |
||
| 519 | $this->loadConfiguration($this->container, 'geocoder_invalid'); |
||
| 520 | $this->container->compile(); |
||
| 521 | } |
||
| 522 | |||
| 523 | public function testTimeZone() |
||
| 524 | { |
||
| 525 | $this->loadConfiguration($this->container, 'time_zone'); |
||
| 526 | $this->container->compile(); |
||
| 527 | |||
| 528 | $timeZone = $this->container->get('ivory.google_map.time_zone'); |
||
| 529 | |||
| 530 | $this->assertInstanceOf(TimeZoneService::class, $timeZone); |
||
| 531 | $this->assertSame($this->client, $timeZone->getClient()); |
||
| 532 | $this->assertSame($this->messageFactory, $timeZone->getMessageFactory()); |
||
| 533 | $this->assertTrue($timeZone->isHttps()); |
||
| 534 | $this->assertSame(TimeZoneService::FORMAT_JSON, $timeZone->getFormat()); |
||
| 535 | $this->assertFalse($timeZone->hasBusinessAccount()); |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @expectedException \InvalidArgumentException |
||
| 540 | * @expectedExceptionMessage The http scheme is not supported. |
||
| 541 | */ |
||
| 542 | public function testTimeZoneHttps() |
||
| 543 | { |
||
| 544 | $this->loadConfiguration($this->container, 'time_zone_https'); |
||
| 545 | $this->container->compile(); |
||
| 546 | |||
| 547 | $this->container->get('ivory.google_map.time_zone'); |
||
| 548 | } |
||
| 549 | |||
| 550 | public function testTimeZoneFormat() |
||
| 551 | { |
||
| 552 | $this->loadConfiguration($this->container, 'time_zone_format'); |
||
| 553 | $this->container->compile(); |
||
| 554 | |||
| 555 | $this->assertSame(TimeZoneService::FORMAT_XML, $this->container->get('ivory.google_map.time_zone')->getFormat()); |
||
| 556 | } |
||
| 557 | |||
| 558 | public function testTimeZoneApiKey() |
||
| 559 | { |
||
| 560 | $this->loadConfiguration($this->container, 'time_zone_api_key'); |
||
| 561 | $this->container->compile(); |
||
| 562 | |||
| 563 | $this->assertSame('key', $this->container->get('ivory.google_map.time_zone')->getKey()); |
||
| 564 | } |
||
| 565 | |||
| 566 | public function testTimeZoneBusinessAccount() |
||
| 567 | { |
||
| 568 | $this->loadConfiguration($this->container, 'time_zone_business_account'); |
||
| 569 | $this->container->compile(); |
||
| 570 | |||
| 571 | $timeZone = $this->container->get('ivory.google_map.time_zone'); |
||
| 572 | |||
| 573 | $this->assertTrue($timeZone->hasBusinessAccount()); |
||
| 574 | $this->assertSame('my-client', $timeZone->getBusinessAccount()->getClientId()); |
||
| 575 | $this->assertSame('my-secret', $timeZone->getBusinessAccount()->getSecret()); |
||
| 576 | $this->assertFalse($timeZone->getBusinessAccount()->hasChannel()); |
||
| 577 | } |
||
| 578 | |||
| 579 | public function testTimeZoneBusinessAccountChannel() |
||
| 580 | { |
||
| 581 | $this->loadConfiguration($this->container, 'time_zone_business_account_channel'); |
||
| 582 | $this->container->compile(); |
||
| 583 | |||
| 584 | $timeZone = $this->container->get('ivory.google_map.time_zone'); |
||
| 585 | |||
| 586 | $this->assertTrue($timeZone->hasBusinessAccount()); |
||
| 587 | $this->assertSame('my-client', $timeZone->getBusinessAccount()->getClientId()); |
||
| 588 | $this->assertSame('my-secret', $timeZone->getBusinessAccount()->getSecret()); |
||
| 589 | $this->assertSame('my-channel', $timeZone->getBusinessAccount()->getChannel()); |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 594 | */ |
||
| 595 | public function testTimeZoneBusinessAccountInvalid() |
||
| 596 | { |
||
| 597 | $this->loadConfiguration($this->container, 'time_zone_business_account_invalid'); |
||
| 598 | $this->container->compile(); |
||
| 599 | } |
||
| 600 | |||
| 601 | /** |
||
| 602 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 603 | */ |
||
| 604 | public function testTimeZoneInvalid() |
||
| 605 | { |
||
| 606 | $this->loadConfiguration($this->container, 'time_zone_invalid'); |
||
| 607 | $this->container->compile(); |
||
| 608 | } |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @expectedException \RuntimeException |
||
| 612 | * @expectedExceptionMessage No "class" attribute found for the tag "ivory.google_map.helper.renderer.extendable" on the service "acme.map.helper.renderer.extendable". |
||
| 613 | */ |
||
| 614 | public function testMissingExtendableRendererClassTagAttribute() |
||
| 615 | { |
||
| 616 | $this->loadConfiguration($this->container, 'extendable'); |
||
| 617 | $this->container->compile(); |
||
| 618 | } |
||
| 619 | |||
| 620 | /** |
||
| 621 | * @return \PHPUnit_Framework_MockObject_MockObject|HttpClient |
||
| 622 | */ |
||
| 623 | private function createClientMock() |
||
| 624 | { |
||
| 625 | return $this->createMock(HttpClient::class); |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * @return \PHPUnit_Framework_MockObject_MockObject|MessageFactory |
||
| 630 | */ |
||
| 631 | private function createMessageFactoryMock() |
||
| 632 | { |
||
| 633 | return $this->createMock(MessageFactory::class); |
||
| 634 | } |
||
| 635 | } |
||
| 636 |