diff --git a/composer.json b/composer.json index 24e405d9bd..db1e3a4d6b 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ ], "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", - "drupal-phpunit-upgrade": "@composer upgrade phpunit/phpunit --with-dependencies", + "drupal-phpunit-upgrade": "@composer upgrade phpunit/phpunit --with-dependencies --no-progress", "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --", "phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --" }, diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php index 8a0a0f5871..8aaae75609 100644 --- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php +++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php @@ -269,7 +269,7 @@ public function getLinkCombinations() { */ protected function getMockNode($has_field, $comment_status, $form_location, $comment_count) { $node = $this->getMock('\Drupal\node\NodeInterface'); - $node->expects($this->once()) + $node->expects($this->any()) ->method('hasField') ->willReturn($has_field); diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index 04a12b86df..a96b0c69e1 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -367,7 +367,7 @@ protected function getAuthenticatedMockMessage($copy_sender = FALSE) { $recipient->expects($this->once()) ->method('getEmail') ->willReturn('user2@drupal.org'); - $recipient->expects($this->once()) + $recipient->expects($this->any()) ->method('getDisplayName') ->willReturn('user2'); $recipient->expects($this->once()) diff --git a/core/modules/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php index e0e1934502..0ab8ba44fd 100644 --- a/core/modules/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php +++ b/core/modules/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php @@ -20,6 +20,7 @@ class CckFileTest extends MigrateDrupalTestBase { * Tests configurability of file migration name. * * @covers ::__construct + * @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead. */ public function testConfigurableFileMigration() { $migration = Migration::create($this->container, [], 'custom_migration', []); diff --git a/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php b/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php index 5bad279c0d..8781ef11b4 100644 --- a/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php +++ b/core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/CckFileTest.php @@ -17,6 +17,8 @@ class CckFileTest extends UnitTestCase { /** * Tests that alt and title attributes are included in transformed values. + * + * @expectedDeprecation CckFile is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\file\Plugin\migrate\process\d6\FieldFile instead. */ public function testTransformAltTitle() { $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal(); diff --git a/core/modules/link/tests/src/Unit/Plugin/migrate/cckfield/LinkCckTest.php b/core/modules/link/tests/src/Unit/Plugin/migrate/cckfield/LinkCckTest.php index 7029d72412..dc3fe7731e 100644 --- a/core/modules/link/tests/src/Unit/Plugin/migrate/cckfield/LinkCckTest.php +++ b/core/modules/link/tests/src/Unit/Plugin/migrate/cckfield/LinkCckTest.php @@ -46,6 +46,8 @@ protected function setUp() { /** * @covers ::processCckFieldValues + * @expectedDeprecation CckFieldPluginBase is deprecated in Drupal 8.3.x and will be be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase instead. + * @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead. */ public function testProcessCckFieldValues() { $this->plugin->processCckFieldValues($this->migration, 'somefieldname', []); diff --git a/core/modules/migrate/tests/src/Kernel/process/DownloadTest.php b/core/modules/migrate/tests/src/Kernel/process/DownloadTest.php index 576539eb3f..ee56e32c52 100644 --- a/core/modules/migrate/tests/src/Kernel/process/DownloadTest.php +++ b/core/modules/migrate/tests/src/Kernel/process/DownloadTest.php @@ -9,7 +9,6 @@ use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use GuzzleHttp\Client; -use GuzzleHttp\Psr7\Response; /** * Tests the download process plugin. @@ -100,14 +99,8 @@ public function testWriteProtectedDestination() { * The local URI of the downloaded file. */ protected function doTransform($destination_uri, $configuration = []) { - // The HTTP client will return a file with contents 'It worked!' - $body = fopen('data://text/plain;base64,SXQgd29ya2VkIQ==', 'r'); - // Prepare a mock HTTP client. $this->container->set('http_client', $this->getMock(Client::class)); - $this->container->get('http_client') - ->method('get') - ->willReturn(new Response(200, [], $body)); // Instantiate the plugin statically so it can pull dependencies out of // the container. diff --git a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index 2fe4a8335d..a24313f4af 100644 --- a/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -134,8 +134,6 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE); - $cache_contexts_manager->expects($this->any()) - ->method('validate_tokens'); $container = new Container(); $container->set('cache_contexts_manager', $cache_contexts_manager); \Drupal::setContainer($container); diff --git a/core/modules/taxonomy/tests/src/Functional/LegacyTest.php b/core/modules/taxonomy/tests/src/Functional/EarlyDateTest.php similarity index 95% rename from core/modules/taxonomy/tests/src/Functional/LegacyTest.php rename to core/modules/taxonomy/tests/src/Functional/EarlyDateTest.php index 667ed5542f..e4490f3431 100644 --- a/core/modules/taxonomy/tests/src/Functional/LegacyTest.php +++ b/core/modules/taxonomy/tests/src/Functional/EarlyDateTest.php @@ -11,7 +11,7 @@ * * @group taxonomy */ -class LegacyTest extends TaxonomyTestBase { +class EarlyDateTest extends TaxonomyTestBase { /** * Modules to enable. @@ -51,7 +51,7 @@ protected function setUp() { /** * Test taxonomy functionality with nodes prior to 1970. */ - public function testTaxonomyLegacyNode() { + public function testTaxonomyEarlyDateNode() { // Posts an article with a taxonomy term and a date prior to 1970. $date = new DrupalDateTime('1969-01-01 00:00:00'); $edit = []; diff --git a/core/modules/tour/tests/src/Functional/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php index 522e8e6f36..2d06d586e8 100644 --- a/core/modules/tour/tests/src/Functional/TourTestBase.php +++ b/core/modules/tour/tests/src/Functional/TourTestBase.php @@ -50,14 +50,13 @@ public function assertTourTips($tips = []) { // Check for corresponding page elements. $total = 0; $modals = 0; - $raw_content = $this->getSession()->getPage()->getContent(); foreach ($tips as $tip) { if (!empty($tip['data-id'])) { - $elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $raw_content, TRUE); + $elements = $this->getSession()->getPage()->find('css', '#' . $tip['data-id']); $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); } elseif (!empty($tip['data-class'])) { - $elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $raw_content, TRUE); + $elements = $this->getSession()->getPage()->find('css', '.' . $tip['data-class']); $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); } else { diff --git a/core/modules/views/tests/src/Functional/Update/LegacyBulkFormUpdateTest.php b/core/modules/views/tests/src/Functional/Update/BulkFormUpdateTest.php similarity index 94% rename from core/modules/views/tests/src/Functional/Update/LegacyBulkFormUpdateTest.php rename to core/modules/views/tests/src/Functional/Update/BulkFormUpdateTest.php index 75e2b54b65..5db54d2c67 100644 --- a/core/modules/views/tests/src/Functional/Update/LegacyBulkFormUpdateTest.php +++ b/core/modules/views/tests/src/Functional/Update/BulkFormUpdateTest.php @@ -10,7 +10,7 @@ * * @group views */ -class LegacyBulkFormUpdateTest extends UpdatePathTestBase { +class BulkFormUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} diff --git a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php index 9323b04438..f9bd6d2f1b 100644 --- a/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/Block/ViewsBlockTest.php @@ -70,7 +70,7 @@ protected function setUp() { $this->executable = $this->getMockBuilder('Drupal\views\ViewExecutable') ->disableOriginalConstructor() - ->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage']) + ->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage', 'getShowAdminLinks']) ->getMock(); $this->executable->expects($this->any()) ->method('setDisplay') diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 83e43605fe..d9a8ba0cab 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -497,6 +497,11 @@ protected function setUp() { if ($disable_gc) { gc_enable(); } + + // Ensure that the test is not marked as risky because of no assertions. In + // PHPIUnit 6 tests that only make assertions using $this->assertSession() + // can be marked as risky. + $this->addToAssertionCount(1); } /** diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index c2d43db027..1e2fbfec8b 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -990,7 +990,7 @@ protected function getCollection($collection, $resolve = TRUE) { * @param string $message * @param int $exception_code */ - private function setExpectedException($class, $message = '', $exception_code = NULL) { + public function setExpectedException($class, $message = '', $exception_code = NULL) { if (method_exists($this, 'expectException')) { $this->expectException($class); if (!empty($message)) { diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php index 6a2cf46673..aee8d09318 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php @@ -71,10 +71,16 @@ public function testGetContextValue($expected, $context_value, $is_required, $da // Set expectation for exception. if ($is_required) { - $this->setExpectedException( - 'Drupal\Component\Plugin\Exception\ContextException', - sprintf("The %s context is required and not present.", $data_type) - ); + 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->setExpectedException( + 'Drupal\Component\Plugin\Exception\ContextException', + 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 b6bb32c841..00e407215d 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php @@ -35,7 +35,7 @@ public function testGetPluginClassWithValidArrayPluginDefinition() { */ public function testGetPluginClassWithValidObjectPluginDefinition() { $plugin_class = Cherry::class; - $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); @@ -60,7 +60,7 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() { * @covers ::getPluginClass */ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() { - $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.'); DefaultFactory::getPluginClass('cherry', $plugin_definition); } @@ -82,7 +82,7 @@ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition( */ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() { $plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit'; - $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); @@ -109,7 +109,7 @@ public function testGetPluginClassWithInterfaceWithArrayPluginDefinition() { */ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() { $plugin_class = Cherry::class; - $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); @@ -136,7 +136,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDef */ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() { $plugin_class = Kale::class; - $plugin_definition = $this->getMock(PluginDefinitionInterface::class); + $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock(); $plugin_definition->expects($this->atLeastOnce()) ->method('getClass') ->willReturn($plugin_class); @@ -144,4 +144,26 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class); } + /** + * Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. + * + * @param mixed $class + * @param string $message + * @param int $exception_code + */ + public 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/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php index c37a4b5a18..1a5c36e7b8 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php @@ -69,7 +69,12 @@ 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. - $this->setExpectedException(PluginNotFoundException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(PluginNotFoundException::class); + } + else { + $this->setExpectedException(PluginNotFoundException::class); + } $method_ref->invoke($trait, $definitions, $plugin_id, TRUE); } @@ -106,7 +111,12 @@ public function testGetDefinitionException($expected, $definitions, $plugin_id) ->method('getDefinitions') ->willReturn($definitions); // Call getDefinition(), with $exception_on_invalid always TRUE. - $this->setExpectedException(PluginNotFoundException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(PluginNotFoundException::class); + } + else { + $this->setExpectedException(PluginNotFoundException::class); + } $trait->getDefinition($plugin_id, TRUE); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php index 7e8fbefd1d..20d2f76edf 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php @@ -123,7 +123,12 @@ 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') { - $this->setExpectedException('\ReflectionException'); + if (method_exists($this, 'expectException')) { + $this->expectException('\ReflectionException'); + } + else { + $this->setExpectedException('\ReflectionException'); + } } // Finally invoke getInstanceArguments() on our mocked factory. diff --git a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php index cbb9d7e8eb..aea1779841 100644 --- a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php @@ -26,7 +26,12 @@ class ColorTest extends TestCase { */ public function testHexToRgb($value, $expected, $invalid = FALSE) { if ($invalid) { - $this->setExpectedException('InvalidArgumentException'); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + } + else { + $this->setExpectedException('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 c87628f75c..80208ef294 100644 --- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php @@ -77,7 +77,12 @@ public function testHmacBase64($data, $key, $expected_hmac) { * Key to use in hashing process. */ public function testHmacBase64Invalid($data, $key) { - $this->setExpectedException(\InvalidArgumentException::class); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + } + else { + $this->setExpectedException('InvalidArgumentException'); + } Crypt::hmacBase64($data, $key); } diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php index 64f0eaac1b..7523c8be06 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php @@ -62,7 +62,12 @@ public function testRandomNameException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - $this->setExpectedException(\RuntimeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + } + else { + $this->setExpectedException(\RuntimeException::class); + } for ($i = 0; $i <= 100; $i++) { $str = $random->name(1, TRUE); $names[$str] = TRUE; @@ -78,7 +83,12 @@ public function testRandomStringException() { // There are fewer than 100 possibilities so an exception should occur to // prevent infinite loops. $random = new Random(); - $this->setExpectedException(\RuntimeException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + } + else { + $this->setExpectedException(\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 49d08333ef..ef46b7963a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php @@ -17,7 +17,12 @@ class RectangleTest extends TestCase { * @covers ::rotate */ public function testWrongWidth() { - $this->setExpectedException(\InvalidArgumentException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + } + else { + $this->setExpectedException(\InvalidArgumentException::class); + } $rect = new Rectangle(-40, 20); } @@ -27,7 +32,12 @@ public function testWrongWidth() { * @covers ::rotate */ public function testWrongHeight() { - $this->setExpectedException(\InvalidArgumentException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + } + else { + $this->setExpectedException(\InvalidArgumentException::class); + } $rect = new Rectangle(40, 0); } diff --git a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php index 7f249d9bea..f811c16c15 100644 --- a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php @@ -37,7 +37,7 @@ protected function tearDown() { * @covers ::isSafe */ public function testIsSafe() { - $safe_string = $this->getMock('\Drupal\Component\Render\MarkupInterface'); + $safe_string = $this->getMockBuilder('\Drupal\Component\Render\MarkupInterface')->getMock(); $this->assertTrue(SafeMarkup::isSafe($safe_string)); $string_object = new SafeMarkupTestString('test'); $this->assertFalse(SafeMarkup::isSafe($string_object)); diff --git a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php index 6bfc6cb0d2..ba1757ffc5 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php @@ -33,7 +33,12 @@ protected function setUp() { */ public function testStatus($value, $expected, $invalid = FALSE) { if ($invalid) { - $this->setExpectedException('InvalidArgumentException'); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + } + else { + $this->setExpectedException('InvalidArgumentException'); + } } Unicode::setStatus($value); $this->assertEquals($expected, Unicode::getStatus()); diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php index db78cd9458..d185219c9a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php @@ -578,7 +578,12 @@ public function providerTestExternalIsLocal() { * @dataProvider providerTestExternalIsLocalInvalid */ public function testExternalIsLocalInvalid($url, $base_url) { - $this->setExpectedException(\InvalidArgumentException::class); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + } + else { + $this->setExpectedException(\InvalidArgumentException::class); + } UrlHelper::externalIsLocal($url, $base_url); } diff --git a/core/tests/Drupal/Tests/Core/Listeners/DrupalStandardsListenerDeprecationTest.php b/core/tests/Drupal/Tests/Core/Listeners/DrupalStandardsListenerDeprecationTest.php index 61b62118af..ad3930440b 100644 --- a/core/tests/Drupal/Tests/Core/Listeners/DrupalStandardsListenerDeprecationTest.php +++ b/core/tests/Drupal/Tests/Core/Listeners/DrupalStandardsListenerDeprecationTest.php @@ -21,6 +21,7 @@ * would trigger another deprecation error. * * @group Listeners + * @group legacy * * @coversDefaultClass \Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass */ @@ -29,6 +30,8 @@ class DrupalStandardsListenerDeprecationTest extends UnitTestCase { /** * Exercise DrupalStandardsListener's coverage validation. * + * @expectedDeprecation Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass is deprecated. + * * @covers ::testFunction */ public function testDeprecation() { diff --git a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php index 2512602afa..0f934ebf8e 100644 --- a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php +++ b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php @@ -102,12 +102,12 @@ public function testSortLoggers() { */ public function providerTestLog() { $account_mock = $this->getMock('Drupal\Core\Session\AccountInterface'); - $account_mock->expects($this->exactly(2)) + $account_mock->expects($this->any()) ->method('id') ->will($this->returnValue(1)); - $request_mock = $this->getMock('Symfony\Component\HttpFoundation\Request'); - $request_mock->expects($this->exactly(2)) + $request_mock = $this->getMock('Symfony\Component\HttpFoundation\Request', ['getClientIp']); + $request_mock->expects($this->any()) ->method('getClientIp') ->will($this->returnValue('127.0.0.1')); $request_mock->headers = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag'); diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php index 929930a521..e6215caac8 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php @@ -76,12 +76,6 @@ protected function setUp() { $language_manager->expects($this->any()) ->method('getLanguageTypes') ->will($this->returnValue([LanguageInterface::TYPE_INTERFACE])); - $language_manager->expects($this->any()) - ->method('getNegotiationMethods') - ->will($this->returnValue($method_definitions)); - $language_manager->expects($this->any()) - ->method('getNegotiationMethodInstance') - ->will($this->returnValue($method_instance)); $method_instance->setLanguageManager($language_manager); $this->languageManager = $language_manager; diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php index 2190d53918..7dead3d32e 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php @@ -104,6 +104,7 @@ public function testSetContextValueCacheableDependency() { $container = new Container(); $cache_context_manager = $this->getMockBuilder('Drupal\Core\Cache\CacheContextsManager') ->disableOriginalConstructor() + ->setMethods(['validateTokens']) ->getMock(); $container->set('cache_contexts_manager', $cache_context_manager); $cache_context_manager->expects($this->any()) diff --git a/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php b/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php index 1fca8179a8..a881e7c2ce 100644 --- a/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php +++ b/core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php @@ -38,6 +38,7 @@ public function testMerge(BubbleableMetadata $a, CacheableMetadata $b, Bubbleabl if (!$b instanceof BubbleableMetadata) { $renderer = $this->getMockBuilder('Drupal\Core\Render\Renderer') ->disableOriginalConstructor() + ->setMethods(['mergeAttachments']) ->getMock(); $renderer->expects($this->never()) ->method('mergeAttachments'); diff --git a/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php b/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php index 621003f6b3..7871d69c10 100644 --- a/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php +++ b/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php @@ -64,6 +64,21 @@ public function getMock($originalClassName) { */ class Phpunit5TestClass { public function createMock($originalClassName) { + throw new \Exception('This method should never be called'); + } + + public function getMockbuilder() { + return new Mockbuilder(); + } + +} + +class Mockbuilder { + public function __call($name, $arguments) { + return $this; + } + + public function getMock() { return 'PHPUnit 5'; } diff --git a/core/tests/TestSuites/TestSuiteBase.php b/core/tests/TestSuites/TestSuiteBase.php index 82a13ba255..5deeb8a612 100644 --- a/core/tests/TestSuites/TestSuiteBase.php +++ b/core/tests/TestSuites/TestSuiteBase.php @@ -3,11 +3,12 @@ namespace Drupal\Tests\TestSuites; use Drupal\simpletest\TestDiscovery; +use PHPUnit\Framework\TestSuite; /** * Base class for Drupal test suites. */ -abstract class TestSuiteBase extends \PHPUnit_Framework_TestSuite { +abstract class TestSuiteBase extends TestSuite { /** * Finds extensions in a Drupal installation.