Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
68 * @covers ::__construct | 68 * @covers ::__construct |
69 */ | 69 */ |
70 public function testConstruct() { | 70 public function testConstruct() { |
71 $container_definition = $this->getMockContainerDefinition(); | 71 $container_definition = $this->getMockContainerDefinition(); |
72 $container_definition['machine_format'] = !$this->machineFormat; | 72 $container_definition['machine_format'] = !$this->machineFormat; |
73 $this->setExpectedException(InvalidArgumentException::class); | 73 if (method_exists($this, 'expectException')) { |
74 $this->expectException(InvalidArgumentException::class); | |
75 } | |
76 else { | |
77 $this->setExpectedException(InvalidArgumentException::class); | |
78 } | |
74 $container = new $this->containerClass($container_definition); | 79 $container = new $this->containerClass($container_definition); |
75 } | 80 } |
76 | 81 |
77 /** | 82 /** |
78 * Tests that Container::getParameter() works properly. | 83 * Tests that Container::getParameter() works properly. |
91 * @covers ::getParameter | 96 * @covers ::getParameter |
92 * @covers ::getParameterAlternatives | 97 * @covers ::getParameterAlternatives |
93 * @covers ::getAlternatives | 98 * @covers ::getAlternatives |
94 */ | 99 */ |
95 public function testGetParameterIfNotFound() { | 100 public function testGetParameterIfNotFound() { |
96 $this->setExpectedException(ParameterNotFoundException::class); | 101 if (method_exists($this, 'expectException')) { |
102 $this->expectException(ParameterNotFoundException::class); | |
103 } | |
104 else { | |
105 $this->setExpectedException(ParameterNotFoundException::class); | |
106 } | |
97 $this->container->getParameter('parameter_that_does_not_exist'); | 107 $this->container->getParameter('parameter_that_does_not_exist'); |
98 } | 108 } |
99 | 109 |
100 /** | 110 /** |
101 * Tests that Container::getParameter() works properly for NULL parameters. | 111 * Tests that Container::getParameter() works properly for NULL parameters. |
102 * | 112 * |
103 * @covers ::getParameter | 113 * @covers ::getParameter |
104 */ | 114 */ |
105 public function testGetParameterIfNotFoundBecauseNull() { | 115 public function testGetParameterIfNotFoundBecauseNull() { |
106 $this->setExpectedException(ParameterNotFoundException::class); | 116 if (method_exists($this, 'expectException')) { |
117 $this->expectException(ParameterNotFoundException::class); | |
118 } | |
119 else { | |
120 $this->setExpectedException(ParameterNotFoundException::class); | |
121 } | |
107 $this->container->getParameter(NULL); | 122 $this->container->getParameter(NULL); |
108 } | 123 } |
109 | 124 |
110 /** | 125 /** |
111 * Tests that Container::hasParameter() works properly. | 126 * Tests that Container::hasParameter() works properly. |
135 * | 150 * |
136 * @covers ::setParameter | 151 * @covers ::setParameter |
137 */ | 152 */ |
138 public function testSetParameterWithFrozenContainer() { | 153 public function testSetParameterWithFrozenContainer() { |
139 $this->container = new $this->containerClass($this->containerDefinition); | 154 $this->container = new $this->containerClass($this->containerDefinition); |
140 $this->setExpectedException(LogicException::class); | 155 if (method_exists($this, 'expectException')) { |
156 $this->expectException(LogicException::class); | |
157 } | |
158 else { | |
159 $this->setExpectedException(LogicException::class); | |
160 } | |
141 $this->container->setParameter('some_config', 'new_value'); | 161 $this->container->setParameter('some_config', 'new_value'); |
142 } | 162 } |
143 | 163 |
144 /** | 164 /** |
145 * Tests that Container::get() works properly. | 165 * Tests that Container::get() works properly. |
240 * Tests that Container::get() for circular dependencies works properly. | 260 * Tests that Container::get() for circular dependencies works properly. |
241 * @covers ::get | 261 * @covers ::get |
242 * @covers ::createService | 262 * @covers ::createService |
243 */ | 263 */ |
244 public function testGetForCircularServices() { | 264 public function testGetForCircularServices() { |
245 $this->setExpectedException(ServiceCircularReferenceException::class); | 265 if (method_exists($this, 'expectException')) { |
266 $this->expectException(ServiceCircularReferenceException::class); | |
267 } | |
268 else { | |
269 $this->setExpectedException(ServiceCircularReferenceException::class); | |
270 } | |
246 $this->container->get('circular_dependency'); | 271 $this->container->get('circular_dependency'); |
247 } | 272 } |
248 | 273 |
249 /** | 274 /** |
250 * Tests that Container::get() for non-existent services works properly. | 275 * Tests that Container::get() for non-existent services works properly. |
253 * @covers ::createService | 278 * @covers ::createService |
254 * @covers ::getAlternatives | 279 * @covers ::getAlternatives |
255 * @covers ::getServiceAlternatives | 280 * @covers ::getServiceAlternatives |
256 */ | 281 */ |
257 public function testGetForNonExistantService() { | 282 public function testGetForNonExistantService() { |
258 $this->setExpectedException(ServiceNotFoundException::class); | 283 if (method_exists($this, 'expectException')) { |
284 $this->expectException(ServiceNotFoundException::class); | |
285 } | |
286 else { | |
287 $this->setExpectedException(ServiceNotFoundException::class); | |
288 } | |
259 $this->container->get('service_not_exists'); | 289 $this->container->get('service_not_exists'); |
260 } | 290 } |
261 | 291 |
262 /** | 292 /** |
263 * Tests that Container::get() for a serialized definition works properly. | 293 * Tests that Container::get() for a serialized definition works properly. |
302 $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); | 332 $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); |
303 $this->assertNull($service, 'Service is NULL.'); | 333 $this->assertNull($service, 'Service is NULL.'); |
304 | 334 |
305 // Reset the service. | 335 // Reset the service. |
306 $this->container->set('service_parameter_not_exists', NULL); | 336 $this->container->set('service_parameter_not_exists', NULL); |
307 $this->setExpectedException(InvalidArgumentException::class); | 337 if (method_exists($this, 'expectException')) { |
338 $this->expectException(InvalidArgumentException::class); | |
339 } | |
340 else { | |
341 $this->setExpectedException(InvalidArgumentException::class); | |
342 } | |
308 $this->container->get('service_parameter_not_exists'); | 343 $this->container->get('service_parameter_not_exists'); |
309 } | 344 } |
310 | 345 |
311 /** | 346 /** |
312 * Tests that Container::get() for non-existent parameters works properly. | 347 * Tests that Container::get() for non-existent parameters works properly. |
314 * @covers ::get | 349 * @covers ::get |
315 * @covers ::createService | 350 * @covers ::createService |
316 * @covers ::resolveServicesAndParameters | 351 * @covers ::resolveServicesAndParameters |
317 */ | 352 */ |
318 public function testGetForNonExistantParameterDependencyWithException() { | 353 public function testGetForNonExistantParameterDependencyWithException() { |
319 $this->setExpectedException(InvalidArgumentException::class); | 354 if (method_exists($this, 'expectException')) { |
355 $this->expectException(InvalidArgumentException::class); | |
356 } | |
357 else { | |
358 $this->setExpectedException(InvalidArgumentException::class); | |
359 } | |
320 $this->container->get('service_parameter_not_exists'); | 360 $this->container->get('service_parameter_not_exists'); |
321 } | 361 } |
322 | 362 |
323 /** | 363 /** |
324 * Tests that Container::get() for non-existent dependencies works properly. | 364 * Tests that Container::get() for non-existent dependencies works properly. |
339 * @covers ::createService | 379 * @covers ::createService |
340 * @covers ::resolveServicesAndParameters | 380 * @covers ::resolveServicesAndParameters |
341 * @covers ::getAlternatives | 381 * @covers ::getAlternatives |
342 */ | 382 */ |
343 public function testGetForNonExistantServiceDependencyWithException() { | 383 public function testGetForNonExistantServiceDependencyWithException() { |
344 $this->setExpectedException(ServiceNotFoundException::class); | 384 if (method_exists($this, 'expectException')) { |
385 $this->expectException(ServiceNotFoundException::class); | |
386 } | |
387 else { | |
388 $this->setExpectedException(ServiceNotFoundException::class); | |
389 } | |
345 $this->container->get('service_dependency_not_exists'); | 390 $this->container->get('service_dependency_not_exists'); |
346 } | 391 } |
347 | 392 |
348 /** | 393 /** |
349 * Tests that Container::get() for non-existent services works properly. | 394 * Tests that Container::get() for non-existent services works properly. |
359 * Tests that Container::get() for NULL service works properly. | 404 * Tests that Container::get() for NULL service works properly. |
360 * @covers ::get | 405 * @covers ::get |
361 * @covers ::createService | 406 * @covers ::createService |
362 */ | 407 */ |
363 public function testGetForNonExistantNULLService() { | 408 public function testGetForNonExistantNULLService() { |
364 $this->setExpectedException(ServiceNotFoundException::class); | 409 if (method_exists($this, 'expectException')) { |
410 $this->expectException(ServiceNotFoundException::class); | |
411 } | |
412 else { | |
413 $this->setExpectedException(ServiceNotFoundException::class); | |
414 } | |
365 $this->container->get(NULL); | 415 $this->container->get(NULL); |
366 } | 416 } |
367 | 417 |
368 /** | 418 /** |
369 * Tests multiple Container::get() calls for non-existing dependencies work. | 419 * Tests multiple Container::get() calls for non-existing dependencies work. |
385 * @covers ::createService | 435 * @covers ::createService |
386 * @covers ::getAlternatives | 436 * @covers ::getAlternatives |
387 */ | 437 */ |
388 public function testGetForNonExistantServiceWithExceptionOnSecondCall() { | 438 public function testGetForNonExistantServiceWithExceptionOnSecondCall() { |
389 $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.'); | 439 $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.'); |
390 $this->setExpectedException(ServiceNotFoundException::class); | 440 if (method_exists($this, 'expectException')) { |
441 $this->expectException(ServiceNotFoundException::class); | |
442 } | |
443 else { | |
444 $this->setExpectedException(ServiceNotFoundException::class); | |
445 } | |
391 $this->container->get('service_not_exists'); | 446 $this->container->get('service_not_exists'); |
392 } | 447 } |
393 | 448 |
394 /** | 449 /** |
395 * Tests that Container::get() for aliased services works properly. | 450 * Tests that Container::get() for aliased services works properly. |
421 * | 476 * |
422 * @covers ::get | 477 * @covers ::get |
423 * @covers ::createService | 478 * @covers ::createService |
424 */ | 479 */ |
425 public function testGetForSyntheticServiceWithException() { | 480 public function testGetForSyntheticServiceWithException() { |
426 $this->setExpectedException(RuntimeException::class); | 481 if (method_exists($this, 'expectException')) { |
482 $this->expectException(RuntimeException::class); | |
483 } | |
484 else { | |
485 $this->setExpectedException(RuntimeException::class); | |
486 } | |
427 $this->container->get('synthetic'); | 487 $this->container->get('synthetic'); |
428 } | 488 } |
429 | 489 |
430 /** | 490 /** |
431 * Tests that Container::get() for services with file includes works. | 491 * Tests that Container::get() for services with file includes works. |
460 * | 520 * |
461 * @covers ::get | 521 * @covers ::get |
462 * @covers ::createService | 522 * @covers ::createService |
463 */ | 523 */ |
464 public function testGetForWrongFactory() { | 524 public function testGetForWrongFactory() { |
465 $this->setExpectedException(RuntimeException::class); | 525 if (method_exists($this, 'expectException')) { |
526 $this->expectException(RuntimeException::class); | |
527 } | |
528 else { | |
529 $this->setExpectedException(RuntimeException::class); | |
530 } | |
466 $this->container->get('wrong_factory'); | 531 $this->container->get('wrong_factory'); |
467 } | 532 } |
468 | 533 |
469 /** | 534 /** |
470 * Tests Container::get() for factories via services (Symfony 2.7.0). | 535 * Tests Container::get() for factories via services (Symfony 2.7.0). |
498 * | 563 * |
499 * @covers ::get | 564 * @covers ::get |
500 * @covers ::createService | 565 * @covers ::createService |
501 */ | 566 */ |
502 public function testGetForConfiguratorWithException() { | 567 public function testGetForConfiguratorWithException() { |
503 $this->setExpectedException(InvalidArgumentException::class); | 568 if (method_exists($this, 'expectException')) { |
569 $this->expectException(InvalidArgumentException::class); | |
570 } | |
571 else { | |
572 $this->setExpectedException(InvalidArgumentException::class); | |
573 } | |
504 $this->container->get('configurable_service_exception'); | 574 $this->container->get('configurable_service_exception'); |
505 } | 575 } |
506 | 576 |
507 /** | 577 /** |
508 * Tests that Container::get() for configurable services works. | 578 * Tests that Container::get() for configurable services works. |
596 * @covers ::get | 666 * @covers ::get |
597 * @covers ::createService | 667 * @covers ::createService |
598 * @covers ::resolveServicesAndParameters | 668 * @covers ::resolveServicesAndParameters |
599 */ | 669 */ |
600 public function testResolveServicesAndParametersForInvalidArgument() { | 670 public function testResolveServicesAndParametersForInvalidArgument() { |
601 $this->setExpectedException(InvalidArgumentException::class); | 671 if (method_exists($this, 'expectException')) { |
672 $this->expectException(InvalidArgumentException::class); | |
673 } | |
674 else { | |
675 $this->setExpectedException(InvalidArgumentException::class); | |
676 } | |
602 $this->container->get('invalid_argument_service'); | 677 $this->container->get('invalid_argument_service'); |
603 } | 678 } |
604 | 679 |
605 /** | 680 /** |
606 * Tests that invalid arguments throw an Exception. | 681 * Tests that invalid arguments throw an Exception. |
610 * @covers ::resolveServicesAndParameters | 685 * @covers ::resolveServicesAndParameters |
611 */ | 686 */ |
612 public function testResolveServicesAndParametersForInvalidArguments() { | 687 public function testResolveServicesAndParametersForInvalidArguments() { |
613 // In case the machine-optimized format is not used, we need to simulate the | 688 // In case the machine-optimized format is not used, we need to simulate the |
614 // test failure. | 689 // test failure. |
615 $this->setExpectedException(InvalidArgumentException::class); | 690 if (method_exists($this, 'expectException')) { |
691 $this->expectException(InvalidArgumentException::class); | |
692 } | |
693 else { | |
694 $this->setExpectedException(InvalidArgumentException::class); | |
695 } | |
616 if (!$this->machineFormat) { | 696 if (!$this->machineFormat) { |
617 throw new InvalidArgumentException('Simulating the test failure.'); | 697 throw new InvalidArgumentException('Simulating the test failure.'); |
618 } | 698 } |
619 $this->container->get('invalid_arguments_service'); | 699 $this->container->get('invalid_arguments_service'); |
620 } | 700 } |