diff --git a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php index d89290e01e307652415abcf1e71aa33dabe3e267..dcad80f8dac6b93882fb6edaab8dbaae85de3dcb 100644 --- a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php +++ b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php @@ -58,14 +58,8 @@ public function testHas() { * @covers ::setStandalone */ public function testSetStandaloneException() { - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); - } - else { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); - } + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest must implement Zend\Feed\Reader\ExtensionManagerInterface or Zend\Feed\Writer\ExtensionManagerInterface'); $bridge = new ZfExtensionManagerSfContainer(); $bridge->setStandalone(static::class); } @@ -74,14 +68,8 @@ public function testSetStandaloneException() { * @covers ::get */ public function testGetContainerException() { - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceNotFoundException::class); - $this->expectExceptionMessage('You have requested a non-existent service "test.foo".'); - } - else { - $this->expectException(ServiceNotFoundException::class); - $this->expectExceptionMessage('You have requested a non-existent service "test.foo".'); - } + $this->expectException(ServiceNotFoundException::class); + $this->expectExceptionMessage('You have requested a non-existent service "test.foo".'); $container = new ContainerBuilder(); $bridge = new ZfExtensionManagerSfContainer('test.'); $bridge->setContainer($container); diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index eac4743b8fc5315cbb653ce157e79b6d40b590da..ca280d582b0ab0f0b7ac0700087296d1f816d647 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -87,14 +87,8 @@ public function testDateDiff($input1, $input2, $absolute, \DateInterval $expecte * @dataProvider providerTestInvalidDateDiff */ public function testInvalidDateDiff($input1, $input2, $absolute) { - if (method_exists($this, 'expectException')) { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); - } - else { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); - } + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); $interval = $input1->diff($input2, $absolute); } @@ -111,12 +105,7 @@ public function testInvalidDateDiff($input1, $input2, $absolute) { * @dataProvider providerTestInvalidDateArrays */ public function testInvalidDateArrays($input, $timezone, $class) { - if (method_exists($this, 'expectException')) { - $this->expectException($class); - } - else { - $this->expectException($class); - } + $this->expectException($class); $this->assertInstanceOf( '\Drupal\Component\DateTimePlus', DateTimePlus::createFromArray($input, $timezone) @@ -254,12 +243,7 @@ public function testDateFormat($input, $timezone, $format, $format_date, $expect * @dataProvider providerTestInvalidDates */ public function testInvalidDates($input, $timezone, $format, $message, $class) { - if (method_exists($this, 'expectException')) { - $this->expectException($class); - } - else { - $this->expectException($class); - } + $this->expectException($class); DateTimePlus::createFromFormat($format, $input, $timezone); } @@ -817,12 +801,7 @@ public function testValidateFormat() { // Parse the same date with ['validate_format' => TRUE] and make sure we // get the expected exception. - if (method_exists($this, 'expectException')) { - $this->expectException(\UnexpectedValueException::class); - } - else { - $this->expectException(\UnexpectedValueException::class); - } + $this->expectException(\UnexpectedValueException::class); $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]); } @@ -881,14 +860,8 @@ public function testChainableNonChainable() { * @covers ::__call */ public function testChainableNonCallable() { - if (method_exists($this, 'expectException')) { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); - } - else { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); - } + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); $date = new DateTimePlus('now', 'Australia/Sydney'); $date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent(); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 217ed1f37322fe36ba5e79950460d9a659a59bde..f2fc10dd7b8eb72ed71eb9c1ebfab8be334227a0 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -70,12 +70,7 @@ protected function setUp() { public function testConstruct() { $container_definition = $this->getMockContainerDefinition(); $container_definition['machine_format'] = !$this->machineFormat; - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $container = new $this->containerClass($container_definition); } @@ -98,12 +93,7 @@ public function testGetParameter() { * @covers ::getAlternatives */ public function testGetParameterIfNotFound() { - if (method_exists($this, 'expectException')) { - $this->expectException(ParameterNotFoundException::class); - } - else { - $this->expectException(ParameterNotFoundException::class); - } + $this->expectException(ParameterNotFoundException::class); $this->container->getParameter('parameter_that_does_not_exist'); } @@ -113,12 +103,7 @@ public function testGetParameterIfNotFound() { * @covers ::getParameter */ public function testGetParameterIfNotFoundBecauseNull() { - if (method_exists($this, 'expectException')) { - $this->expectException(ParameterNotFoundException::class); - } - else { - $this->expectException(ParameterNotFoundException::class); - } + $this->expectException(ParameterNotFoundException::class); $this->container->getParameter(NULL); } @@ -152,12 +137,7 @@ public function testSetParameterWithUnfrozenContainer() { */ public function testSetParameterWithFrozenContainer() { $this->container = new $this->containerClass($this->containerDefinition); - if (method_exists($this, 'expectException')) { - $this->expectException(LogicException::class); - } - else { - $this->expectException(LogicException::class); - } + $this->expectException(LogicException::class); $this->container->setParameter('some_config', 'new_value'); } @@ -262,12 +242,7 @@ public function testHasForAliasedService() { * @covers ::createService */ public function testGetForCircularServices() { - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceCircularReferenceException::class); - } - else { - $this->expectException(ServiceCircularReferenceException::class); - } + $this->expectException(ServiceCircularReferenceException::class); $this->container->get('circular_dependency'); } @@ -280,12 +255,7 @@ public function testGetForCircularServices() { * @covers ::getServiceAlternatives */ public function testGetForNonExistantService() { - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceNotFoundException::class); - } - else { - $this->expectException(ServiceNotFoundException::class); - } + $this->expectException(ServiceNotFoundException::class); $this->container->get('service_not_exists'); } @@ -334,12 +304,7 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() { // Reset the service. $this->container->set('service_parameter_not_exists', NULL); - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $this->container->get('service_parameter_not_exists'); } @@ -351,12 +316,7 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() { * @covers ::resolveServicesAndParameters */ public function testGetForNonExistantParameterDependencyWithException() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $this->container->get('service_parameter_not_exists'); } @@ -381,12 +341,7 @@ public function testGetForNonExistantServiceDependency() { * @covers ::getAlternatives */ public function testGetForNonExistantServiceDependencyWithException() { - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceNotFoundException::class); - } - else { - $this->expectException(ServiceNotFoundException::class); - } + $this->expectException(ServiceNotFoundException::class); $this->container->get('service_dependency_not_exists'); } @@ -406,12 +361,7 @@ public function testGetForNonExistantServiceWhenUsingNull() { * @covers ::createService */ public function testGetForNonExistantNULLService() { - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceNotFoundException::class); - } - else { - $this->expectException(ServiceNotFoundException::class); - } + $this->expectException(ServiceNotFoundException::class); $this->container->get(NULL); } @@ -437,12 +387,7 @@ public function testGetForNonExistantServiceMultipleTimes() { */ public function testGetForNonExistantServiceWithExceptionOnSecondCall() { $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.'); - if (method_exists($this, 'expectException')) { - $this->expectException(ServiceNotFoundException::class); - } - else { - $this->expectException(ServiceNotFoundException::class); - } + $this->expectException(ServiceNotFoundException::class); $this->container->get('service_not_exists'); } @@ -478,12 +423,7 @@ public function testGetForSyntheticService() { * @covers ::createService */ public function testGetForSyntheticServiceWithException() { - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - } - else { - $this->expectException(RuntimeException::class); - } + $this->expectException(RuntimeException::class); $this->container->get('synthetic'); } @@ -522,12 +462,7 @@ public function testGetForInstantiationWithVariousArgumentLengths() { * @covers ::createService */ public function testGetForWrongFactory() { - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - } - else { - $this->expectException(RuntimeException::class); - } + $this->expectException(RuntimeException::class); $this->container->get('wrong_factory'); } @@ -565,12 +500,7 @@ public function testGetForFactoryClass() { * @covers ::createService */ public function testGetForConfiguratorWithException() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $this->container->get('configurable_service_exception'); } @@ -668,12 +598,7 @@ public function testResolveServicesAndParametersForOptionalServiceDependencies() * @covers ::resolveServicesAndParameters */ public function testResolveServicesAndParametersForInvalidArgument() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $this->container->get('invalid_argument_service'); } @@ -687,12 +612,7 @@ public function testResolveServicesAndParametersForInvalidArgument() { public function testResolveServicesAndParametersForInvalidArguments() { // In case the machine-optimized format is not used, we need to simulate the // test failure. - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); if (!$this->machineFormat) { throw new InvalidArgumentException('Simulating the test failure.'); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 67989f168cb9a904f9a3fb254664c038bc7ae585..e1560787ac65dc642145ed85b9fffb16416cd9f0 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -545,12 +545,7 @@ public function testGetServiceDefinitionForDecoratedService() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidArgumentException::class); - } - else { - $this->expectException(InvalidArgumentException::class); - } + $this->expectException(InvalidArgumentException::class); $this->dumper->getArray(); } @@ -567,12 +562,7 @@ public function testGetServiceDefinitionForExpression() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - } - else { - $this->expectException(RuntimeException::class); - } + $this->expectException(RuntimeException::class); $this->dumper->getArray(); } @@ -589,12 +579,7 @@ public function testGetServiceDefinitionForObject() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - } - else { - $this->expectException(RuntimeException::class); - } + $this->expectException(RuntimeException::class); $this->dumper->getArray(); } @@ -611,12 +596,7 @@ public function testGetServiceDefinitionForResource() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - if (method_exists($this, 'expectException')) { - $this->expectException(RuntimeException::class); - } - else { - $this->expectException(RuntimeException::class); - } + $this->expectException(RuntimeException::class); $this->dumper->getArray(); } diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php index b68f5db6a33e658557dcfa28d5174675ca4eeca2..ebcfdcb475d3068bb7af944023533a427d6f5540 100644 --- a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php @@ -124,14 +124,8 @@ public function testDiscoveryAlternateId() { * @covers ::getIdentifier */ public function testDiscoveryNoIdException() { - if (method_exists($this, 'expectException')) { - $this->expectException(DiscoveryException::class); - $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); - } - else { - $this->expectException(DiscoveryException::class); - $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); - } + $this->expectException(DiscoveryException::class); + $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); vfsStream::setup('modules', NULL, [ 'test_1' => [ 'item_1.test.yml' => "", @@ -151,14 +145,8 @@ public function testDiscoveryNoIdException() { * @covers ::findAll */ public function testDiscoveryInvalidYamlException() { - if (method_exists($this, 'expectException')) { - $this->expectException(DiscoveryException::class); - $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); - } - else { - $this->expectException(DiscoveryException::class); - $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); - } + $this->expectException(DiscoveryException::class); + $this->expectExceptionMessage('The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); vfsStream::setup('modules', NULL, [ 'test_1' => [ 'item_1.test.yml' => "id: invalid\nfoo : [bar}", diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index caee00b053cbd733632065f66843cb8d15d3eb54..c3849efa862a51a11fd250b506918667397bc27d 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -59,14 +59,8 @@ public function testGet() { */ public function testGetNoPrefix() { FileCacheFactory::setPrefix(NULL); - if (method_exists($this, 'expectException')) { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Required prefix configuration is missing'); - } - else { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('Required prefix configuration is missing'); - } + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Required prefix configuration is missing'); FileCacheFactory::get('test_foo_settings', []); } diff --git a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php index ccf1b68813b0a8d103b71d660a4c4c6520b8ce28..90c50943ed38d2754fc3fd1b98be2f727027f796 100644 --- a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php +++ b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php @@ -45,13 +45,7 @@ protected function setUp() { * @covers ::getURI */ public function testGetUriException() { - if (method_exists($this, 'expectException')) { - $this->expectException(\Exception::class, 'No URI set.'); - } - else { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('No URI set.'); - } + $this->expectException(\Exception::class, 'No URI set.'); $this->poWriter->getURI(); } @@ -62,13 +56,7 @@ public function testGetUriException() { */ public function testWriteItem($poContent, $expected, $long) { if ($long) { - if (method_exists($this, 'expectException')) { - $this->expectException(\Exception::class, 'Unable to write data:'); - } - else { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('Unable to write data:'); - } + $this->expectException(\Exception::class, 'Unable to write data:'); } // Limit the file system quota to make the write fail on long strings. @@ -107,13 +95,7 @@ public function providerWriteData() { * @covers ::close */ public function testCloseException() { - if (method_exists($this, 'expectException')) { - $this->expectException(\Exception::class, 'Cannot close stream that is not open.'); - } - else { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('Cannot close stream that is not open.'); - } + $this->expectException(\Exception::class, 'Cannot close stream that is not open.'); $this->poWriter->close(); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php index 0d17487165bf041a22e7a9c21bcb8b7615cdcad1..bdcaaad680812b25311a245bb31882c58a4778c5 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php @@ -71,14 +71,8 @@ public function testGetContextValue($expected, $context_value, $is_required, $da // Set expectation for exception. if ($is_required) { - if (method_exists($this, 'expectException')) { - $this->expectException('Drupal\Component\Plugin\Exception\ContextException'); - $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type)); - } - else { - $this->expectException('Drupal\Component\Plugin\Exception\ContextException'); - $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type)); - } + $this->expectException('Drupal\Component\Plugin\Exception\ContextException'); + $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type)); } // Exercise getContextValue(). diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php index 01dbe12adb9801e2f9e8cd4da4f64fa31814b6be..11f6c04abf350340f88865f9efb81f2c854753e8 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -50,14 +50,8 @@ public function testGetPluginClassWithValidObjectPluginDefinition() { * @covers ::getPluginClass */ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() { - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); - } - else { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); - } + $this->expectException(PluginException::class); + $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); DefaultFactory::getPluginClass('corn', []); } @@ -67,15 +61,10 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() { * @covers ::getPluginClass */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { - $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); - } - else { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); - } + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class) + ->getMock(); + $this->expectException(PluginException::class); + $this->expectExceptionMessage('The plugin (corn) did not specify an instance class.'); DefaultFactory::getPluginClass('corn', $plugin_definition); } @@ -85,14 +74,8 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { * @covers ::getPluginClass */ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() { - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); - } - else { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); - } + $this->expectException(PluginException::class); + $this->expectExceptionMessage('Plugin (carrot) instance class "Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot" does not exist.'); DefaultFactory::getPluginClass('carrot', ['class' => 'Drupal\Tests\Component\Plugin\Fixtures\vegetable\Carrot']); } @@ -107,12 +90,7 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - } - else { - $this->expectException(PluginException::class); - } + $this->expectException(PluginException::class); DefaultFactory::getPluginClass('carrot', $plugin_definition); } @@ -150,14 +128,8 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() { * @covers ::getPluginClass */ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() { - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); - } - else { - $this->expectException(PluginException::class); - $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); - } + $this->expectException(PluginException::class); + $this->expectExceptionMessage('Plugin "corn" (Drupal\Tests\Component\Plugin\Fixtures\vegetable\Broccoli) must implement interface Drupal\Tests\Component\Plugin\Fixtures\vegetable\VegetableInterface.'); DefaultFactory::getPluginClass('corn', ['class' => Broccoli::class], VegetableInterface::class); } @@ -172,12 +144,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); - if (method_exists($this, 'expectException')) { - $this->expectException(PluginException::class); - } - else { - $this->expectException(PluginException::class); - } + $this->expectException(PluginException::class); DefaultFactory::getPluginClass('corn', $plugin_definition, VegetableInterface::class); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index e713ecc738296c120ba7260c1e2183c1f9911a03..b5c7bbbf0b467aadb948a9626fb28c370c6b35a3 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -69,12 +69,7 @@ public function testDoGetDefinitionException($expected, $definitions, $plugin_id $method_ref = new \ReflectionMethod($trait, 'doGetDefinition'); $method_ref->setAccessible(TRUE); // Call doGetDefinition, with $exception_on_invalid always TRUE. - if (method_exists($this, 'expectException')) { - $this->expectException(PluginNotFoundException::class); - } - else { - $this->expectException(PluginNotFoundException::class); - } + $this->expectException(PluginNotFoundException::class); $method_ref->invoke($trait, $definitions, $plugin_id, TRUE); } @@ -111,12 +106,7 @@ public function testGetDefinitionException($expected, $definitions, $plugin_id) ->method('getDefinitions') ->willReturn($definitions); // Call getDefinition(), with $exception_on_invalid always TRUE. - if (method_exists($this, 'expectException')) { - $this->expectException(PluginNotFoundException::class); - } - else { - $this->expectException(PluginNotFoundException::class); - } + $this->expectException(PluginNotFoundException::class); $trait->getDefinition($plugin_id, TRUE); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php index e23a8201b554d2d1f74785d55b006421cba90a48..69daab46dd18c114834a7bf8d80d80acedd9ffca 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php @@ -100,12 +100,7 @@ public function testGetDefinition($expected, $has_register_definitions, $excepti $ref_decorated->setValue($mock_decorator, $mock_decorated); if ($exception_on_invalid) { - if (method_exists($this, 'expectException')) { - $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); - } - else { - $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); - } + $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException'); } // Exercise getDefinition(). It calls parent::getDefinition(). diff --git a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php index d57ffcfc64ca8cd28145025a91680f2f60b060e6..1e40e69e74ddb4290ce18850680b75db4d49f11d 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php @@ -123,12 +123,7 @@ public function testGetInstanceArguments($expected, $reflector_name, $plugin_id, // us to use one data set for this test method as well as // testCreateInstance(). if ($plugin_id == 'arguments_no_constructor') { - if (method_exists($this, 'expectException')) { - $this->expectException('\ReflectionException'); - } - else { - $this->expectException('\ReflectionException'); - } + $this->expectException('\ReflectionException'); } // Finally invoke getInstanceArguments() on our mocked factory. diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php index 3d9692b4525916cd9c63081a2fec5bd5485c91b7..954ff70110c902d7aab4f0406f996a596c727f32 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php @@ -121,14 +121,8 @@ public function testGetInstanceWithoutMapperShouldThrowException() { $manager = $this->getMockBuilder(PluginManagerBase::class) ->getMockForAbstractClass(); // Set the expected exception thrown by ::getInstance. - if (method_exists($this, 'expectException')) { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); - } - else { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); - } + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage(sprintf('%s does not support this method unless %s::$mapper is set.', get_class($manager), get_class($manager))); $manager->getInstance($options); } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php index 910a6356b86be4910c41385e4697cf65515b2306..5512a1c62c1cc52ffe6688bb412fdd376af0096b 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -87,12 +87,7 @@ public function testGetFileExtension() { * @covers ::errorHandler */ public function testError() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidDataTypeException::class); - } - else { - $this->expectException(InvalidDataTypeException::class); - } + $this->expectException(InvalidDataTypeException::class); YamlPecl::decode('foo: [ads'); } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php index eeedf538d6a57e23c4a7e63f4ffecc1d6512360e..cbf7afbf46af854c839c9751897e0e648a49704c 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -59,12 +59,7 @@ public function testGetFileExtension() { * @covers ::decode */ public function testError() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidDataTypeException::class); - } - else { - $this->expectException(InvalidDataTypeException::class); - } + $this->expectException(InvalidDataTypeException::class); YamlSymfony::decode('foo: [ads'); } @@ -74,14 +69,8 @@ public function testError() { * @covers ::encode */ public function testObjectSupportDisabled() { - if (method_exists($this, 'expectException')) { - $this->expectException(InvalidDataTypeException::class); - $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); - } - else { - $this->expectException(InvalidDataTypeException::class); - $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); - } + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); $object = new \stdClass(); $object->foo = 'bar'; YamlSymfony::encode([$object]); diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php index ffa92efd660fdd597684eacc5a86c9e93390ebc9..f68013bfdcd550aead1b578dc1c99b00cf975db5 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php @@ -102,13 +102,8 @@ public function testObjectSupportDisabledPecl() { * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl() */ public function testObjectSupportDisabledSymfony() { - if (method_exists($this, 'setExpectedExceptionRegExp')) { - $this->setExpectedExceptionRegExp(InvalidDataTypeException::class, '/^Object support when parsing a YAML file has been disabled/'); - } - else { - $this->expectException(InvalidDataTypeException::class); - $this->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/'); - } + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/'); $object = new \stdClass(); $object->foo = 'bar'; // In core all Yaml encoding is done via Symfony and it does not support diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index b6aad1759b5c3fc03fd52cb9a7ad065b80932b67..207a4874857533696d18d9262a0764d41a6a65be 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -128,14 +128,8 @@ public function testGetWildcardArgumentNoTypehint() { $resolver = new ArgumentsResolver([], [], $wildcards); $callable = function ($route) {}; - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$route" argument.'); - } - else { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$route" argument.'); - } + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$route" argument.'); $resolver->getArguments($callable); } @@ -163,14 +157,8 @@ public function testHandleNotUpcastedArgument() { $resolver = new ArgumentsResolver($scalars, $objects, []); $callable = function (\stdClass $foo) {}; - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$foo" argument.'); - } - else { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$foo" argument.'); - } + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); $resolver->getArguments($callable); } @@ -181,14 +169,8 @@ public function testHandleNotUpcastedArgument() { */ public function testHandleUnresolvedArgument($callable) { $resolver = new ArgumentsResolver([], [], []); - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$foo" argument.'); - } - else { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('requires a value for the "$foo" argument.'); - } + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); $resolver->getArguments($callable); } diff --git a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php index ea0153b3e98ed6b40ed4b6900cb0730af9156cec..9a628f96f8240c35d4690d1a6b2fd5c42a57db9c 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php @@ -80,12 +80,7 @@ public function providerTestValidateHex() { */ public function testHexToRgb($value, $expected, $invalid = FALSE) { if ($invalid) { - if (method_exists($this, 'expectException')) { - $this->expectException('InvalidArgumentException'); - } - else { - $this->expectException('InvalidArgumentException'); - } + $this->expectException('InvalidArgumentException'); } $this->assertSame($expected, Color::hexToRgb($value)); } diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php index 14fdb8407b96bd425a8454246582ea0c7ddeedee..0f812ed5849a469e737b847719d1c9ac38210e6f 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -71,12 +71,7 @@ public function testHmacBase64($data, $key, $expected_hmac) { * Key to use in hashing process. */ public function testHmacBase64Invalid($data, $key) { - if (method_exists($this, 'expectException')) { - $this->expectException('InvalidArgumentException'); - } - else { - $this->expectException('InvalidArgumentException'); - } + $this->expectException('InvalidArgumentException'); Crypt::hmacBase64($data, $key); } diff --git a/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php index 8fd53b6933ee6ae2d3a2b3fc6c02cf9b9fb343b4..fc657794b7cd90963729370d84757dba0cba2d81 100644 --- a/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php @@ -32,14 +32,8 @@ public function testIsValid() { */ public function testIsValidException() { $validator = new EmailValidator(); - if (method_exists($this, 'expectException')) { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); - } - else { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); - } + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Calling \Drupal\Component\Utility\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196'); $validator->isValid('example@example.com', (new RFCValidation())); } diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index 327287bb695ae88c15e312d755551b6b936948ac..ee3c5f66ba078ebba75c3fcabad3f9480bed51a6 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -343,12 +343,7 @@ public function testTransformRootRelativeUrlsToAbsolute($html, $scheme_and_host, * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { - if (method_exists($this, 'expectException')) { - $this->expectException(\AssertionError::class); - } - else { - $this->expectException(\AssertionError::class); - } + $this->expectException(\AssertionError::class); Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); } diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index 88a16bbb2801a0658473f3511d586fa076683434..ea61abc5882d4545479a2751721be294bc45c5d0 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -62,12 +62,7 @@ public function testRandomNameException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - } - else { - $this->expectException(\RuntimeException::class); - } + $this->expectException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->name(1, TRUE); $names[$str] = TRUE; @@ -83,12 +78,7 @@ public function testRandomStringException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - if (method_exists($this, 'expectException')) { - $this->expectException(\RuntimeException::class); - } - else { - $this->expectException(\RuntimeException::class); - } + $this->expectException(\RuntimeException::class); for ($i = 0; $i <= 100; $i++) { $str = $random->string(1, TRUE); $names[$str] = TRUE; diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php index 1cd7f387eeea52475b99c85982bf0563714bdd7c..cbdbe2088422eff53375b982196494619aee5970 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -17,12 +17,7 @@ class RectangleTest extends TestCase { * @covers ::rotate */ public function testWrongWidth() { - if (method_exists($this, 'expectException')) { - $this->expectException(\InvalidArgumentException::class); - } - else { - $this->expectException(\InvalidArgumentException::class); - } + $this->expectException(\InvalidArgumentException::class); $rect = new Rectangle(-40, 20); } @@ -32,12 +27,7 @@ public function testWrongWidth() { * @covers ::rotate */ public function testWrongHeight() { - if (method_exists($this, 'expectException')) { - $this->expectException(\InvalidArgumentException::class); - } - else { - $this->expectException(\InvalidArgumentException::class); - } + $this->expectException(\InvalidArgumentException::class); $rect = new Rectangle(40, 0); } diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index ff1b423084908532889fe1deed15aa99f766efe4..594344f39e51f1bc85c768d3719b600c7bea2c26 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -582,12 +582,7 @@ public function providerTestExternalIsLocal() { * @dataProvider providerTestExternalIsLocalInvalid */ public function testExternalIsLocalInvalid($url, $base_url) { - if (method_exists($this, 'expectException')) { - $this->expectException(\InvalidArgumentException::class); - } - else { - $this->expectException(\InvalidArgumentException::class); - } + $this->expectException(\InvalidArgumentException::class); UrlHelper::externalIsLocal($url, $base_url); }