diff --git a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php index 1569411353..5d3a20b6a6 100644 --- a/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php +++ b/core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php @@ -49,6 +49,7 @@ public function setUpDisplayVariant($configuration = [], $definition = []) { $container = new Container(); $cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager') ->disableOriginalConstructor() + ->setMethods(['assertValidTokens']) ->getMock(); $container->set('cache_contexts_manager', $cache_context_manager); $cache_context_manager->expects($this->any()) @@ -209,9 +210,6 @@ public function testBuild(array $blocks_config, $visible_block_count, array $exp $title_block_plugin = $this->getMock('Drupal\Core\Block\TitleBlockPluginInterface'); foreach ($blocks_config as $block_id => $block_config) { $block = $this->getMock('Drupal\block\BlockInterface'); - $block->expects($this->any()) - ->method('getContexts') - ->willReturn([]); $block->expects($this->atLeastOnce()) ->method('getPlugin') ->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : ($block_config[3] ? $title_block_plugin : $block_plugin))); diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php index 2fefc0148c..d72000b868 100644 --- a/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php @@ -217,7 +217,7 @@ public function testInvalidStateMultilingual() { /** * Tests that content without prior moderation information can be moderated. */ - public function testLegacyContent() { + public function testExistingContentWithNoModeration() { $node_type = NodeType::create([ 'type' => 'example', ]); @@ -251,7 +251,7 @@ public function testLegacyContent() { /** * Tests that content without prior moderation information can be translated. */ - public function testLegacyMultilingualContent() { + public function testExistingMultilingualContentWithNoModeration() { // Enable French. ConfigurableLanguage::createFromLangcode('fr')->save(); diff --git a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php index 20d7662d29..558cecb94a 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php @@ -78,11 +78,6 @@ protected function getMigration() { $configuration = &$this->migrationConfiguration; - $migration->method('getHighWaterProperty') - ->willReturnCallback(function () use ($configuration) { - return isset($configuration['high_water_property']) ? $configuration['high_water_property'] : ''; - }); - $migration->method('set') ->willReturnCallback(function ($argument, $value) use (&$configuration) { $configuration[$argument] = $value; diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index 95ee39fd3a..38e610c3b5 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -188,7 +188,7 @@ public function testInvalidLinkNotExistsExact() { /** * Tests legacy text asserts. */ - public function testLegacyTextAsserts() { + public function testTextAsserts() { $this->drupalGet('test-encoded'); $dangerous = 'Bad html '; $sanitized = Html::escape($dangerous); @@ -202,7 +202,7 @@ public function testLegacyTextAsserts() { /** * Tests legacy field asserts which use xpath directly. */ - public function testLegacyXpathAsserts() { + public function testXpathAsserts() { $this->drupalGet('test-field-xpath'); $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL); $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one'); @@ -245,7 +245,7 @@ public function testLegacyXpathAsserts() { /** * Tests legacy field asserts using textfields. */ - public function testLegacyFieldAssertsForTextfields() { + public function testFieldAssertsForTextfields() { $this->drupalGet('test-field-xpath'); // *** 1. assertNoField(). @@ -387,7 +387,7 @@ public function testLegacyFieldAssertsForTextfields() { /** * Tests legacy field asserts for options field type. */ - public function testLegacyFieldAssertsForOptions() { + public function testFieldAssertsForOptions() { $this->drupalGet('test-field-xpath'); // Option field type. @@ -443,7 +443,7 @@ public function testLegacyFieldAssertsForOptions() { /** * Tests legacy field asserts for button field type. */ - public function testLegacyFieldAssertsForButton() { + public function testFieldAssertsForButton() { $this->drupalGet('test-field-xpath'); $this->assertFieldById('edit-save', NULL); @@ -485,7 +485,7 @@ public function testLegacyFieldAssertsForButton() { /** * Tests legacy field asserts for checkbox field type. */ - public function testLegacyFieldAssertsForCheckbox() { + public function testFieldAssertsForCheckbox() { $this->drupalGet('test-field-xpath'); // Part 1 - Test by name. diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index b12ba60b8a..83e43605fe 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -66,6 +66,7 @@ createUser as drupalCreateUser; } use XdebugRequestTrait; + use Phpunit5FCTrait; /** * The database prefix of this test run. diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php index 297125bf63..b89d351c75 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @@ -87,7 +87,13 @@ public function testDateDiff($input1, $input2, $absolute, \DateInterval $expecte * @dataProvider providerTestInvalidDateDiff */ public function testInvalidDateDiff($input1, $input2, $absolute) { - $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); + 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->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object'); + } $interval = $input1->diff($input2, $absolute); } @@ -104,7 +110,12 @@ public function testInvalidDateDiff($input1, $input2, $absolute) { * @dataProvider providerTestInvalidDateArrays */ public function testInvalidDateArrays($input, $timezone, $class) { - $this->setExpectedException($class); + if (method_exists($this, 'expectException')) { + $this->expectException($class); + } + else { + $this->setExpectedException($class); + } $this->assertInstanceOf( '\Drupal\Component\DateTimePlus', DateTimePlus::createFromArray($input, $timezone) @@ -242,7 +253,12 @@ public function testDateFormat($input, $timezone, $format, $format_date, $expect * @dataProvider providerTestInvalidDates */ public function testInvalidDates($input, $timezone, $format, $message, $class) { - $this->setExpectedException($class); + if (method_exists($this, 'expectException')) { + $this->expectException($class); + } + else { + $this->setExpectedException($class); + } DateTimePlus::createFromFormat($format, $input, $timezone); } @@ -800,7 +816,12 @@ public function testValidateFormat() { // Parse the same date with ['validate_format' => TRUE] and make sure we // get the expected exception. - $this->setExpectedException(\UnexpectedValueException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\UnexpectedValueException::class); + } + else { + $this->setExpectedException(\UnexpectedValueException::class); + } $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]); } @@ -859,7 +880,13 @@ public function testChainableNonChainable() { * @covers ::__call */ public function testChainableNonCallable() { - $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); + if (method_exists($this, 'expectException')) { + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()'); + } + else { + $this->setExpectedException(\BadMethodCallException::class, '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/Datetime/TimeTest.php b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php index 4a5fa80205..29c27b23c7 100644 --- a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php +++ b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php @@ -37,7 +37,12 @@ class TimeTest extends TestCase { protected function setUp() { parent::setUp(); - $this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + if (method_exists($this, 'createMock')) { + $this->requestStack = $this->createMock('Symfony\Component\HttpFoundation\RequestStack'); + } + else { + $this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + } $this->time = new Time($this->requestStack); } diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 0e6a1472cd..c2d43db027 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -983,6 +983,28 @@ protected function getCollection($collection, $resolve = TRUE) { ]; } + /** + * Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. + * + * @param mixed $class + * @param string $message + * @param int $exception_code + */ + private function setExpectedException($class, $message = '', $exception_code = NULL) { + if (method_exists($this, 'expectException')) { + $this->expectException($class); + if (!empty($message)) { + $this->expectExceptionMessage($message); + } + if ($exception_code !== NULL) { + $this->expectExceptionCode($exception_code); + } + } + else { + parent::setExpectedException($class, $message, $exception_code); + } + } + } /** diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 3c44752748..c1b70954d1 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -545,7 +545,12 @@ public function testGetServiceDefinitionForDecoratedService() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(InvalidArgumentException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidArgumentException::class); + } + else { + $this->setExpectedException(InvalidArgumentException::class); + } $this->dumper->getArray(); } @@ -562,7 +567,12 @@ public function testGetServiceDefinitionForExpression() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(RuntimeException::class); + } + else { + $this->setExpectedException(RuntimeException::class); + } $this->dumper->getArray(); } @@ -579,7 +589,12 @@ public function testGetServiceDefinitionForObject() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(RuntimeException::class); + } + else { + $this->setExpectedException(RuntimeException::class); + } $this->dumper->getArray(); } @@ -596,7 +611,12 @@ public function testGetServiceDefinitionForResource() { $services['bar'] = $bar_definition; $this->containerBuilder->getDefinitions()->willReturn($services); - $this->setExpectedException(RuntimeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(RuntimeException::class); + } + else { + $this->setExpectedException(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 86134a7bdf..9ac807d744 100644 --- a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php @@ -124,7 +124,13 @@ public function testDiscoveryAlternateId() { * @covers ::getIdentifier */ public function testDiscoveryNoIdException() { - $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\''); + 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->setExpectedException(DiscoveryException::class, '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' => "", @@ -144,7 +150,13 @@ public function testDiscoveryNoIdException() { * @covers ::findAll */ public function testDiscoveryInvalidYamlException() { - $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML'); + 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->setExpectedException(DiscoveryException::class, '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/EventDispatcher/ContainerAwareEventDispatcherTest.php b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php index ea0685a717..a750ecaf09 100644 --- a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php +++ b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php @@ -38,7 +38,7 @@ public function testGetListenersWithCallables() // When passing in callables exclusively as listeners into the event // dispatcher constructor, the event dispatcher must not attempt to // resolve any services. - $container = $this->getMock(ContainerInterface::class); + $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $container->expects($this->never())->method($this->anything()); $firstListener = new CallableClass(); @@ -73,7 +73,7 @@ public function testDispatchWithCallables() // When passing in callables exclusively as listeners into the event // dispatcher constructor, the event dispatcher must not attempt to // resolve any services. - $container = $this->getMock(ContainerInterface::class); + $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $container->expects($this->never())->method($this->anything()); $firstListener = new CallableClass(); diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php index 995f5fc851..f919598434 100644 --- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php @@ -59,7 +59,13 @@ public function testGet() { */ public function testGetNoPrefix() { FileCacheFactory::setPrefix(NULL); - $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Required prefix configuration is missing'); + } + else { + $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing'); + } FileCacheFactory::get('test_foo_settings', []); } diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php index c2e0a0d888..5a71f48381 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php @@ -87,7 +87,12 @@ public function testGetFileExtension() { * @covers ::errorHandler */ public function testError() { - $this->setExpectedException(InvalidDataTypeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidDataTypeException::class); + } + else { + $this->setExpectedException(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 86c818c18e..d857d097a5 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -59,7 +59,12 @@ public function testGetFileExtension() { * @covers ::decode */ public function testError() { - $this->setExpectedException(InvalidDataTypeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidDataTypeException::class); + } + else { + $this->setExpectedException(InvalidDataTypeException::class); + } YamlSymfony::decode('foo: [ads'); } @@ -69,7 +74,13 @@ public function testError() { * @covers ::encode */ public function testObjectSupportDisabled() { - $this->setExpectedException(InvalidDataTypeException::class, 'Object support when dumping a YAML file has been disabled.'); + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.'); + } + else { + $this->setExpectedException(InvalidDataTypeException::class, '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/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php index f15f14b85a..695edf4ba6 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php @@ -96,9 +96,16 @@ public function testGetWildcardArgument() { * Tests getArgument() with a Route, Request, and Account object. */ public function testGetArgumentOrder() { - $a1 = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); - $a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass'); - $a3 = $this->getMock('\Drupal\Tests\Component\Utility\Test2Interface'); + if (method_exists($this, 'createMock')) { + $a1 = $this->createMock('\Drupal\Tests\Component\Utility\Test1Interface'); + $a2 = $this->createMock('\Drupal\Tests\Component\Utility\TestClass'); + $a3 = $this->createMock('\Drupal\Tests\Component\Utility\Test2Interface'); + } + else { + $a1 = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); + $a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass'); + $a3 = $this->getMock('\Drupal\Tests\Component\Utility\Test2Interface'); + } $objects = [ 't1' => $a1, @@ -123,12 +130,23 @@ public function testGetArgumentOrder() { * Without the typehint, the wildcard object will not be passed to the callable. */ public function testGetWildcardArgumentNoTypehint() { - $a = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); + if (method_exists($this, 'createMock')) { + $a = $this->createMock('\Drupal\Tests\Component\Utility\Test1Interface'); + } + else { + $a = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); + } $wildcards = [$a]; $resolver = new ArgumentsResolver([], [], $wildcards); $callable = function ($route) {}; - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$route" argument.'); + } + else { + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); + } $resolver->getArguments($callable); } @@ -156,7 +174,13 @@ public function testHandleNotUpcastedArgument() { $resolver = new ArgumentsResolver($scalars, $objects, []); $callable = function (\stdClass $foo) {}; - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); + } + else { + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + } $resolver->getArguments($callable); } @@ -167,7 +191,13 @@ public function testHandleNotUpcastedArgument() { */ public function testHandleUnresolvedArgument($callable) { $resolver = new ArgumentsResolver([], [], []); - $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('requires a value for the "$foo" argument.'); + } + else { + $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); + } $resolver->getArguments($callable); } diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index 1860e04105..a8a8af0e6c 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -343,7 +343,12 @@ public function testTransformRootRelativeUrlsToAbsolute($html, $scheme_and_host, * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { - $this->setExpectedException(\AssertionError::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\AssertionError::class); + } + else { + $this->setExpectedException(\AssertionError::class); + } Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); } diff --git a/core/tests/Drupal/Tests/Core/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php b/core/tests/Drupal/Tests/Core/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php index 1ee804d539..a92d76abb7 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php @@ -164,10 +164,6 @@ protected function setUp() { ->willReturnMap([ ['entity_display', $storage_access_control_handler], ]); - $entity_type_manager - ->expects($this->any()) - ->method('getFieldDefinitions') - ->willReturn([]); $entity_type_manager ->expects($this->any()) ->method('getDefinition') diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index ad68e2df68..55928b98a6 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -123,9 +123,6 @@ public function testGetOperations() { $url = $this->getMockBuilder('\Drupal\Core\Url') ->disableOriginalConstructor() ->getMock(); - $url->expects($this->any()) - ->method('toArray') - ->will($this->returnValue([])); $url->expects($this->atLeastOnce()) ->method('mergeOptions') ->with(['query' => ['destination' => '/foo/bar']]); diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 4a2dac5653..846ce0a59f 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -361,7 +361,7 @@ public function testSaveConfigEntity() { $this->assertSame('foo', $entity->getOriginalId()); $expected = ['id' => 'foo']; - $entity->expects($this->once()) + $entity->expects($this->atLeastOnce()) ->method('toArray') ->will($this->returnValue($expected)); diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php index fb1e4f4765..8021989868 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -15,6 +15,8 @@ class_alias('Drupal\Tests\Listeners\Legacy\HtmlOutputPrinter', 'Drupal\Tests\Lis else { /** * Defines a class for providing html output results for functional tests. + * + * @internal */ class HtmlOutputPrinter extends ResultPrinter { use HtmlOutputPrinterTrait; diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php index 0a9cc42dc6..9900685884 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinterTrait.php @@ -4,6 +4,8 @@ /** * Defines a class for providing html output results for functional tests. + * + * @internal */ trait HtmlOutputPrinterTrait { diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php index e5abb6ffc6..7c1f45e38f 100644 --- a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php @@ -6,6 +6,8 @@ /** * Defines a class for providing html output results for functional tests. + * + * @internal */ class HtmlOutputPrinter extends \PHPUnit_TextUI_ResultPrinter { use HtmlOutputPrinterTrait; diff --git a/core/tests/Drupal/Tests/Phpunit5FCTrait.php b/core/tests/Drupal/Tests/Phpunit5FCTrait.php index 9a123ada13..7ace0bf198 100644 --- a/core/tests/Drupal/Tests/Phpunit5FCTrait.php +++ b/core/tests/Drupal/Tests/Phpunit5FCTrait.php @@ -85,7 +85,42 @@ public function getMock($originalClassName, $methods = array(), array $arguments */ public function createMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) { if ($this->isPhpunit5()) { - return parent::createMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget); + $mock = $this->getMockBuilder($originalClassName) + ->setMethods($methods) + ->setConstructorArgs($arguments) + ->setMockClassName($mockClassName) + ->setProxyTarget($proxyTarget); + if ($callOriginalConstructor) { + $mock->enableOriginalConstructor(); + } + else { + $mock->disableOriginalConstructor(); + } + if ($callOriginalClone) { + $mock->enableOriginalClone(); + } + else { + $mock->disableOriginalClone(); + } + if ($callAutoload) { + $mock->enableAutoload(); + } + else { + $mock->disableAutoload(); + } + if ($cloneArguments) { + $mock->enableArgumentCloning(); + } + else { + $mock->disableArgumentCloning(); + } + if ($callOriginalMethods) { + $mock->enableProxyingToOriginalMethods(); + } + else { + $mock->disableProxyingToOriginalMethods(); + } + return $mock->getMock(); } return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget); }