Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / tests / Drupal / Tests / Component / DependencyInjection / ContainerTest.php
index 6cd5575964f34c48a1338419b8f2fefc73a86fc7..577bb8baffd100cea71da45e27c69c476f75000f 100644 (file)
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Component\DependencyInjection;
 
 use Drupal\Component\Utility\Crypt;
+use PHPUnit\Framework\TestCase;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 use Symfony\Component\DependencyInjection\Exception\LogicException;
@@ -21,7 +22,7 @@ use Prophecy\Argument;
  * @coversDefaultClass \Drupal\Component\DependencyInjection\Container
  * @group DependencyInjection
  */
-class ContainerTest extends \PHPUnit_Framework_TestCase {
+class ContainerTest extends TestCase {
 
   /**
    * The tested container.
@@ -69,7 +70,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
   public function testConstruct() {
     $container_definition = $this->getMockContainerDefinition();
     $container_definition['machine_format'] = !$this->machineFormat;
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $container = new $this->containerClass($container_definition);
   }
 
@@ -92,7 +98,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::getAlternatives
    */
   public function testGetParameterIfNotFound() {
-    $this->setExpectedException(ParameterNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ParameterNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ParameterNotFoundException::class);
+    }
     $this->container->getParameter('parameter_that_does_not_exist');
   }
 
@@ -102,7 +113,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::getParameter
    */
   public function testGetParameterIfNotFoundBecauseNull() {
-    $this->setExpectedException(ParameterNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ParameterNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ParameterNotFoundException::class);
+    }
     $this->container->getParameter(NULL);
   }
 
@@ -136,7 +152,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    */
   public function testSetParameterWithFrozenContainer() {
     $this->container = new $this->containerClass($this->containerDefinition);
-    $this->setExpectedException(LogicException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(LogicException::class);
+    }
+    else {
+      $this->setExpectedException(LogicException::class);
+    }
     $this->container->setParameter('some_config', 'new_value');
   }
 
@@ -241,7 +262,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::createService
    */
   public function testGetForCircularServices() {
-    $this->setExpectedException(ServiceCircularReferenceException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceCircularReferenceException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceCircularReferenceException::class);
+    }
     $this->container->get('circular_dependency');
   }
 
@@ -254,7 +280,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::getServiceAlternatives
    */
   public function testGetForNonExistantService() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_not_exists');
   }
 
@@ -303,7 +334,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
 
     // Reset the service.
     $this->container->set('service_parameter_not_exists', NULL);
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -315,7 +351,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::resolveServicesAndParameters
    */
   public function testGetForNonExistantParameterDependencyWithException() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -340,7 +381,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::getAlternatives
    */
   public function testGetForNonExistantServiceDependencyWithException() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_dependency_not_exists');
   }
 
@@ -360,7 +406,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::createService
    */
   public function testGetForNonExistantNULLService() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get(NULL);
   }
 
@@ -386,7 +437,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    */
   public function testGetForNonExistantServiceWithExceptionOnSecondCall() {
     $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.');
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_not_exists');
   }
 
@@ -422,7 +478,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::createService
    */
   public function testGetForSyntheticServiceWithException() {
-    $this->setExpectedException(RuntimeException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(RuntimeException::class);
+    }
+    else {
+      $this->setExpectedException(RuntimeException::class);
+    }
     $this->container->get('synthetic');
   }
 
@@ -461,7 +522,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::createService
    */
   public function testGetForWrongFactory() {
-    $this->setExpectedException(RuntimeException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(RuntimeException::class);
+    }
+    else {
+      $this->setExpectedException(RuntimeException::class);
+    }
     $this->container->get('wrong_factory');
   }
 
@@ -499,7 +565,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::createService
    */
   public function testGetForConfiguratorWithException() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('configurable_service_exception');
   }
 
@@ -516,7 +587,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
     $configurator = $this->prophesize('\Drupal\Tests\Component\DependencyInjection\MockConfiguratorInterface');
     $configurator->configureService(Argument::type('object'))
       ->shouldBeCalled(1)
-      ->will(function($args) use ($container) {
+      ->will(function ($args) use ($container) {
         $args[0]->setContainer($container);
       });
     $container->set('configurator', $configurator->reveal());
@@ -597,7 +668,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
    * @covers ::resolveServicesAndParameters
    */
   public function testResolveServicesAndParametersForInvalidArgument() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('invalid_argument_service');
   }
 
@@ -611,7 +687,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
   public function testResolveServicesAndParametersForInvalidArguments() {
     // In case the machine-optimized format is not used, we need to simulate the
     // test failure.
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     if (!$this->machineFormat) {
       throw new InvalidArgumentException('Simulating the test failure.');
     }
@@ -653,46 +734,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
     $this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.');
   }
 
-  /**
-   * Tests that unsupported methods throw an Exception.
-   *
-   * @covers ::enterScope
-   * @covers ::leaveScope
-   * @covers ::addScope
-   * @covers ::hasScope
-   * @covers ::isScopeActive
-   *
-   * @dataProvider scopeExceptionTestProvider
-   */
-  public function testScopeFunctionsWithException($method, $argument) {
-    $callable = [
-      $this->container,
-      $method,
-    ];
-
-    $this->setExpectedException(\BadMethodCallException::class);
-    $callable($argument);
-  }
-
-  /**
-   * Data provider for scopeExceptionTestProvider().
-   *
-   * @return array[]
-   *   Returns per data set an array with:
-   *     - method name to call
-   *     - argument to pass
-   */
-  public function scopeExceptionTestProvider() {
-    $scope = $this->prophesize('\Symfony\Component\DependencyInjection\ScopeInterface')->reveal();
-    return [
-      ['enterScope', 'test_scope'],
-      ['leaveScope', 'test_scope'],
-      ['hasScope', 'test_scope'],
-      ['isScopeActive', 'test_scope'],
-      ['addScope', $scope],
-    ];
-  }
-
   /**
    * Tests that Container::getServiceIds() works properly.
    *
@@ -754,12 +795,18 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
       ]),
       'properties' => $this->getCollection(['_someProperty' => 'foo']),
       'calls' => [
-        ['setContainer', $this->getCollection([
-          $this->getServiceCall('service_container'),
-        ])],
-        ['setOtherConfigParameter', $this->getCollection([
-          $this->getParameterCall('some_other_config'),
-        ])],
+        [
+          'setContainer',
+          $this->getCollection([
+            $this->getServiceCall('service_container'),
+          ]),
+        ],
+        [
+          'setOtherConfigParameter',
+          $this->getCollection([
+            $this->getParameterCall('some_other_config'),
+          ]),
+        ],
       ],
       'priority' => 0,
     ];
@@ -811,7 +858,8 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
     $services['invalid_argument_service'] = [
       'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
       'arguments' => $this->getCollection([
-        1, // Test passing non-strings, too.
+        // Test passing non-strings, too.
+        1,
         (object) [
           'type' => 'invalid',
         ],
@@ -863,9 +911,12 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
         [NULL, 'bar'],
       ],
       'calls' => [
-        ['setContainer', $this->getCollection([
-          $this->getServiceCall('service_container'),
-        ])],
+        [
+          'setContainer',
+          $this->getCollection([
+            $this->getServiceCall('service_container'),
+          ]),
+        ],
       ],
     ];
 
@@ -942,7 +993,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase {
       'arguments' => [],
       'configurator' => [
         $this->getServiceCall('configurator'),
-        'configureService'
+        'configureService',
       ],
     ];
     $services['configurable_service_exception'] = [
@@ -1072,7 +1123,7 @@ class MockInstantiationService {
 class MockService {
 
   /**
-   * @var ContainerInterface
+   * @var \Symfony\Component\DependencyInjection\ContainerInterface
    */
   protected $container;
 
@@ -1110,7 +1161,7 @@ class MockService {
   /**
    * Sets the container object.
    *
-   * @param ContainerInterface $container
+   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
    *   The container to inject via setter injection.
    */
   public function setContainer(ContainerInterface $container) {
@@ -1120,7 +1171,7 @@ class MockService {
   /**
    * Gets the container object.
    *
-   * @return ContainerInterface
+   * @return \Symfony\Component\DependencyInjection\ContainerInterface
    *   The internally set container.
    */
   public function getContainer() {