diff --git a/composer.json b/composer.json
index 71dcc9605cc5e887b64b361354782fc366933672..3bfb0c7779487ecf7cfd288c6cc884af8da5d58f 100644
--- a/composer.json
+++ b/composer.json
@@ -49,11 +49,11 @@
     },
     "scripts": {
         "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
-        "post-autoload-dump": [
-          "Drupal\\Core\\Composer\\Composer::ensureHtaccess"
-        ],
+        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
         "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
         "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
+        "post-install-cmd": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
+        "drupal-phpunit-upgrade": "@composer update 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/composer.json b/core/composer.json
index 31bc51a0fa84d9acb958b84a220911377098cb59..c4bb384b92a5426ca7631cfbd4094c6086d9e062 100644
--- a/core/composer.json
+++ b/core/composer.json
@@ -44,7 +44,7 @@
         "jcalderonzumba/gastonjs": "^1.0.2",
         "jcalderonzumba/mink-phantomjs-driver": "^0.3.1",
         "mikey179/vfsStream": "^1.2",
-        "phpunit/phpunit": ">=4.8.35 <5",
+        "phpunit/phpunit": "^4.8.35 || ^6.1",
         "phpspec/prophecy": "^1.4",
         "symfony/css-selector": "~3.2.8",
         "symfony/phpunit-bridge": "^3.4.0@beta"
diff --git a/core/lib/Drupal/Core/Composer/Composer.php b/core/lib/Drupal/Core/Composer/Composer.php
index 016f93a348563fedff4cf50db03e7b87b8245b1d..5f3a4a92ab89c190db32f8535ef71eb55921eb14 100644
--- a/core/lib/Drupal/Core/Composer/Composer.php
+++ b/core/lib/Drupal/Core/Composer/Composer.php
@@ -143,6 +143,32 @@ public static function ensureHtaccess(Event $event) {
     }
   }
 
+  /**
+   * Fires the drupal-phpunit-upgrade script event if necessary.
+   *
+   * @param \Composer\Script\Event $event
+   */
+  public static function upgradePHPUnit(Event $event) {
+    $repository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
+    // This is, essentially, a null constraint. We only care whether the package
+    // is present in the vendor directory yet, but findPackage() requires it.
+    $constraint = new Constraint('>', '');
+    $phpunit_package = $repository->findPackage('phpunit/phpunit', $constraint);
+    if (!$phpunit_package) {
+      // There is nothing to do. The user is probably installing using the
+      // --no-dev flag.
+      return;
+    }
+
+    // If the PHP version is 7.2 or above and PHPUnit is less than version 6
+    // call the drupal-phpunit-upgrade script to upgrade PHPUnit.
+    if (version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.2') >= 0 && version_compare($phpunit_package->getVersion(), '6.1') < 0) {
+      $event->getComposer()
+        ->getEventDispatcher()
+        ->dispatchScript('drupal-phpunit-upgrade');
+    }
+  }
+
   /**
    * Remove possibly problematic test files from vendored projects.
    *
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 15694113534b8bcff0fd3c4c961740bf29b4b30e..5d3a20b6a6d4cad83dc13dd8f5939e357a908aed 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/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
index 8a0a0f5871f2a024275588a01755e7f24ded967d..8aaae756098157d62bcdd21503d8fe6682b035d8 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 04a12b86df58117ace64cbffb9e8fbe689ffb545..a96b0c69e12448134650bfe2d9f819ed1ac082d0 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/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php
index 2fefc0148c56a1b483a84c52e64c6f9513e5f522..d72000b868be577c1e3ba6fd72c4ce3270f52329 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/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/process/d6/CckFileTest.php
index e0e1934502859a55c0b6dbba7414ec413c76b565..0ab8ba44fd9bc61e7e920f9e5684fa6576578b84 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 5bad279c0dcea365adc09d121934c5877b716fbe..8781ef11b470fd449ce7d32f039c1ba0eb9cbb93 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/Kernel/Plugin/migrate/cckfield/d7/LinkCckTest.php b/core/modules/link/tests/src/Kernel/Plugin/migrate/cckfield/d7/LinkCckTest.php
index 896c15c9fca01d125d086787df7c83c6367bc784..14345a60ef28b374aacb70279a7778dd1d80368b 100644
--- a/core/modules/link/tests/src/Kernel/Plugin/migrate/cckfield/d7/LinkCckTest.php
+++ b/core/modules/link/tests/src/Kernel/Plugin/migrate/cckfield/d7/LinkCckTest.php
@@ -53,6 +53,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->processFieldInstance($this->migration);
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 7029d72412e9efa9dc1107ee6fc1495195fba686..dc3fe7731ee4ec97fc20f4896723730183ad953f 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 576539eb3feda61dd5be3b208ccf182fe615c5e5..ee56e32c525d42e22852f0c761a61bc5701a401e 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/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php
index 20d7662d2901b9ba6ba1d32e1415dbbd9c54489f..558cecb94af0bbbed26d3f820cb3677614987e3b 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/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/src/Unit/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php
index 2fe4a8335d0a3842d2fa9f7d39d5fd6234c85e81..a24313f4affb81347c628952e44c8ae18d961956 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 667ed5542fc67e09c1490c7d3a22cdb4c6ceaf95..e4490f3431aa778ef91e4f98dc40471f5b2195b6 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/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 75e2b54b65ec7028f16a8545f502eb76d4c89823..5db54d2c67ecee433456b7688ed7cb517be0cb8d 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 9323b04438b20d3807c52c9c04660a95ec80deef..f9bd6d2f1b72af9be108a0edb1debb17461c39a1 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/phpunit.xml.dist b/core/phpunit.xml.dist
index 750c6e2b502e1ff827367c43d56e5929f9a8c8b6..963d921a7e828d25c660f8fdc513f8a2b62a3669 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -8,8 +8,7 @@
 <phpunit bootstrap="tests/bootstrap.php" colors="true"
          beStrictAboutTestsThatDoNotTestAnything="true"
          beStrictAboutOutputDuringTests="true"
-         beStrictAboutChangesToGlobalState="true"
-         checkForUnintentionallyCoveredCode="false">
+         beStrictAboutChangesToGlobalState="true">
 <!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
  https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
  result printer that links to the html output results for functional tests.
@@ -30,7 +29,7 @@
     <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
     <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
     <!-- To disable deprecation testing uncomment the next line. -->
-    <!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
+    <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors"/>
     <!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
     <!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
   </php>
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 5ebf9f0c9fba0a8455a4519c547d40a44a9a4e83..407d87a34f6c665952d74a91ad21f3273e391fa6 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -793,7 +793,11 @@ function simpletest_script_run_one_test($test_id, $test_class) {
       putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
     }
     else {
-      putenv('SYMFONY_DEPRECATIONS_HELPER=strict');
+      // Prevent deprecations caused by vendor code calling deprecated code.
+      // This also prevents mock objects in PHPUnit 6 triggering silenced
+      // deprecations from breaking the test suite. We should consider changing
+      // this to 'strict' once PHPUnit 4 is no longer used.
+      putenv('SYMFONY_DEPRECATIONS_HELPER=weak_vendors');
     }
     if (is_subclass_of($test_class, TestCase::class)) {
       $status = simpletest_script_run_phpunit($test_id, $test_class);
diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
index 95ee39fd3a788391a43ed2664d7ea65537b8d0ad..38e610c3b56611a7546dd66a764551c2066b60ff 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 <script>alert(123);</script>';
     $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/KernelTests/Core/Messenger/LegacyMessengerTest.php b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php
similarity index 98%
rename from core/tests/Drupal/KernelTests/Core/Messenger/LegacyMessengerTest.php
rename to core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php
index 13f10e9c2eb01f4979df8224948b7f770a068286..362069756eae2c8f7b10dac5a95c17ae0b8321d0 100644
--- a/core/tests/Drupal/KernelTests/Core/Messenger/LegacyMessengerTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php
@@ -11,7 +11,7 @@
  * @group Messenger
  * @coversDefaultClass \Drupal\Core\Messenger\LegacyMessenger
  */
-class LegacyMessengerTest extends KernelTestBase {
+class MessengerTest extends KernelTestBase {
 
   /**
    * Retrieves the Messenger service from LegacyMessenger.
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 93df3dbf1319a0ff93a018c15d487f04b39f04a7..3260f6ea016b228f979b06120d886ce15e8d7465 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
+    // PHPUnit 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/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
index 297125bf63edba49257324d799376e73962365a5..b89d351c755c9c3067eb64904fdd91dc16fb9e9d 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 4a5fa80205c27956d97715ba555a708a7cedbc15..ee0a2af36f26b43c1fc528f7fd29ffcd920830e2 100644
--- a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php
+++ b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php
@@ -37,8 +37,7 @@ class TimeTest extends TestCase {
   protected function setUp() {
     parent::setUp();
 
-    $this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
-
+    $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
     $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 0e6a1472cdc536bc689a50a473bddacb17cb786f..1b5b23f347e44661eaaf5f3b32e4a6fdf3e6cdb1 100644
--- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
@@ -70,7 +70,12 @@ protected function setUp() {
   public function testConstruct() {
     $container_definition = $this->getMockContainerDefinition();
     $container_definition['machine_format'] = !$this->machineFormat;
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $container = new $this->containerClass($container_definition);
   }
 
@@ -93,7 +98,12 @@ public function testGetParameter() {
    * @covers ::getAlternatives
    */
   public function testGetParameterIfNotFound() {
-    $this->setExpectedException(ParameterNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ParameterNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ParameterNotFoundException::class);
+    }
     $this->container->getParameter('parameter_that_does_not_exist');
   }
 
@@ -103,7 +113,12 @@ public function testGetParameterIfNotFound() {
    * @covers ::getParameter
    */
   public function testGetParameterIfNotFoundBecauseNull() {
-    $this->setExpectedException(ParameterNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ParameterNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ParameterNotFoundException::class);
+    }
     $this->container->getParameter(NULL);
   }
 
@@ -137,7 +152,12 @@ public function testSetParameterWithUnfrozenContainer() {
    */
   public function testSetParameterWithFrozenContainer() {
     $this->container = new $this->containerClass($this->containerDefinition);
-    $this->setExpectedException(LogicException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(LogicException::class);
+    }
+    else {
+      $this->setExpectedException(LogicException::class);
+    }
     $this->container->setParameter('some_config', 'new_value');
   }
 
@@ -242,7 +262,12 @@ public function testHasForAliasedService() {
    * @covers ::createService
    */
   public function testGetForCircularServices() {
-    $this->setExpectedException(ServiceCircularReferenceException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceCircularReferenceException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceCircularReferenceException::class);
+    }
     $this->container->get('circular_dependency');
   }
 
@@ -255,7 +280,12 @@ public function testGetForCircularServices() {
    * @covers ::getServiceAlternatives
    */
   public function testGetForNonExistantService() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_not_exists');
   }
 
@@ -304,7 +334,12 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
 
     // Reset the service.
     $this->container->set('service_parameter_not_exists', NULL);
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -316,7 +351,12 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
    * @covers ::resolveServicesAndParameters
    */
   public function testGetForNonExistantParameterDependencyWithException() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -341,7 +381,12 @@ public function testGetForNonExistantServiceDependency() {
    * @covers ::getAlternatives
    */
   public function testGetForNonExistantServiceDependencyWithException() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_dependency_not_exists');
   }
 
@@ -361,7 +406,12 @@ public function testGetForNonExistantServiceWhenUsingNull() {
    * @covers ::createService
    */
   public function testGetForNonExistantNULLService() {
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get(NULL);
   }
 
@@ -387,7 +437,12 @@ 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.');
-    $this->setExpectedException(ServiceNotFoundException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(ServiceNotFoundException::class);
+    }
+    else {
+      $this->setExpectedException(ServiceNotFoundException::class);
+    }
     $this->container->get('service_not_exists');
   }
 
@@ -423,7 +478,12 @@ public function testGetForSyntheticService() {
    * @covers ::createService
    */
   public function testGetForSyntheticServiceWithException() {
-    $this->setExpectedException(RuntimeException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(RuntimeException::class);
+    }
+    else {
+      $this->setExpectedException(RuntimeException::class);
+    }
     $this->container->get('synthetic');
   }
 
@@ -462,7 +522,12 @@ public function testGetForInstantiationWithVariousArgumentLengths() {
    * @covers ::createService
    */
   public function testGetForWrongFactory() {
-    $this->setExpectedException(RuntimeException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(RuntimeException::class);
+    }
+    else {
+      $this->setExpectedException(RuntimeException::class);
+    }
     $this->container->get('wrong_factory');
   }
 
@@ -500,7 +565,12 @@ public function testGetForFactoryClass() {
    * @covers ::createService
    */
   public function testGetForConfiguratorWithException() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('configurable_service_exception');
   }
 
@@ -598,7 +668,12 @@ public function testResolveServicesAndParametersForOptionalServiceDependencies()
    * @covers ::resolveServicesAndParameters
    */
   public function testResolveServicesAndParametersForInvalidArgument() {
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     $this->container->get('invalid_argument_service');
   }
 
@@ -612,7 +687,12 @@ public function testResolveServicesAndParametersForInvalidArgument() {
   public function testResolveServicesAndParametersForInvalidArguments() {
     // In case the machine-optimized format is not used, we need to simulate the
     // test failure.
-    $this->setExpectedException(InvalidArgumentException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(InvalidArgumentException::class);
+    }
+    else {
+      $this->setExpectedException(InvalidArgumentException::class);
+    }
     if (!$this->machineFormat) {
       throw new InvalidArgumentException('Simulating the test failure.');
     }
diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
index 3c447527487cb68628c57f28ba2e29cdfca7b44a..c1b70954d11ba8b60250fc3bd3a768bb859eeadf 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/Diff/Engine/DiffOpTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
index 1a649ae510c7733dd7c65a647e517799a827b49e..dbbb6ec08176057fde7bc5b0c3dcd0778caf05ff 100644
--- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
+++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Component\Diff\Engine\DiffOp;
 use PHPUnit\Framework\TestCase;
+use PHPUnit\Framework\Error\Error;
 
 /**
  * Test DiffOp base class.
@@ -24,7 +25,12 @@ class DiffOpTest extends TestCase {
    * @covers ::reverse
    */
   public function testReverse() {
-    $this->setExpectedException(\PHPUnit_Framework_Error::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(Error::class);
+    }
+    else {
+      $this->setExpectedException(\PHPUnit_Framework_Error::class);
+    }
     $op = new DiffOp();
     $result = $op->reverse();
   }
diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
index 86134a7bdf10098c22db00fe917e6154799afb47..9ac807d744d031d456229b9c4b47156fd30a26dd 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 ea0685a7171edb904a75d8e901751cbbfced812a..a750ecaf097b859561b75ecb99df77a2ed3a3530 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 995f5fc8510ea6396b7e537579c2749e4546d171..f9195984341a9d8ceb54cc51100d9e2301e1cbc9 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/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
index 52e1b83c032ed21c5add56482ad1d07635ba1eab..168d1603e3ceb2bdcc9ec9311d11dbb3adceef8a 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
@@ -5,7 +5,7 @@
 use Drupal\Component\PhpStorage\FileStorage;
 use Drupal\Component\Utility\Random;
 use org\bovigo\vfs\vfsStreamDirectory;
-use PHPUnit_Framework_Error_Warning;
+use PHPUnit\Framework\Error\Warning;
 
 /**
  * @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
@@ -99,7 +99,13 @@ public function testCreateDirectoryFailWarning() {
       'bin' => 'test',
     ]);
     $code = "<?php\n echo 'here';";
-    $this->setExpectedException(PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(Warning::class);
+      $this->expectExceptionMessage('mkdir(): Permission Denied');
+    }
+    else {
+      $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'mkdir(): Permission Denied');
+    }
     $storage->save('subdirectory/foo.php', $code);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
index 6a2cf4667321ffa6b6a79d5bf3f7ee587960e94a..aee8d093189308257e09abcd9ab560a1b62b1cf9 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 b6bb32c8415410b37204ab3b1810bb5b23da3fa3..de24172904be897f1d52d5b9c94ee59c2b300334 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);
@@ -50,7 +50,13 @@ public function testGetPluginClassWithValidObjectPluginDefinition() {
    * @covers ::getPluginClass
    */
   public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
-    $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+      $this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.');
+    }
+    else {
+      $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
+    }
     DefaultFactory::getPluginClass('cherry', []);
   }
 
@@ -60,8 +66,14 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
    * @covers ::getPluginClass
    */
   public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
-    $plugin_definition = $this->getMock(PluginDefinitionInterface::class);
-    $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
+    $plugin_definition = $this->getMockBuilder(PluginDefinitionInterface::class)->getMock();
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+      $this->expectExceptionMessage('The plugin (cherry) did not specify an instance class.');
+    }
+    else {
+      $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
+    }
     DefaultFactory::getPluginClass('cherry', $plugin_definition);
   }
 
@@ -71,7 +83,13 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
    * @covers ::getPluginClass
    */
   public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
-    $this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+      $this->expectExceptionMessage('Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
+    }
+    else {
+      $this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
+    }
     DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']);
   }
 
@@ -82,11 +100,16 @@ 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);
-    $this->setExpectedException(PluginException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+    }
+    else {
+      $this->setExpectedException(PluginException::class);
+    }
     DefaultFactory::getPluginClass('kiwifruit', $plugin_definition);
   }
 
@@ -109,7 +132,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);
@@ -125,7 +148,13 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
    */
   public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
     $plugin_class = Kale::class;
-    $this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+      $this->expectExceptionMessage('Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
+    }
+    else {
+      $this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
+    }
     DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class);
   }
 
@@ -136,11 +165,16 @@ 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);
-    $this->setExpectedException(PluginException::class);
+    if (method_exists($this, 'expectException')) {
+      $this->expectException(PluginException::class);
+    }
+    else {
+      $this->setExpectedException(PluginException::class);
+    }
     DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
index c37a4b5a18d3757b8536146cdc9df562823dfa4d..1a5c36e7b85436e0e8672523c88d00d8799a7a72 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/Discovery/StaticDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
index a44721bd9b4e76d49f3981fcc6188cb35b08cf97..5b010930922a17d25766ddc9b38d8b4b6e6deaa7 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
@@ -100,7 +100,12 @@ public function testGetDefinition($expected, $has_register_definitions, $excepti
     $ref_decorated->setValue($mock_decorator, $mock_decorated);
 
     if ($exception_on_invalid) {
-      $this->setExpectedException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
+      if (method_exists($this, 'expectException')) {
+        $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
+      }
+      else {
+        $this->setExpectedException('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 7e8fbefd1d1cb48b334caf6cf49bbcfcc3bb84e8..20d2f76edfc530208ec995ae2c6b62d465b3451d 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/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
index c2e0a0d888ee89247b11ee198825ce3b940dd852..5a71f483810193d20518014de91728905db9c3f4 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 86c818c18eaa39f787798d1d62ca4f018f3d96b4..d857d097a525156ae7a539bbea122a9d1162aafe 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 f15f14b85a4cf94f4d4be47572046fac7b6f6aa1..9099d6fa582a5941a2e8e04941ddcaef663c599b 100644
--- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
@@ -96,9 +96,9 @@ 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');
+    $a1 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock();
+    $a2 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\TestClass')->getMock();
+    $a3 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test2Interface')->getMock();
 
     $objects = [
       't1' => $a1,
@@ -123,12 +123,18 @@ 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');
+    $a = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock();
     $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 +162,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 +179,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/ColorTest.php b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php
index cbb9d7e8eb91d3e7fd46d74cf2c208bcbf2c0870..aea1779841e6a02351c296ba7112d31af710993c 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 c87628f75cda54a31005d1b61cadfba13acfffaf..80208ef294f52ac69af244a8fb5bfe3b2b3e35d5 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/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
index 1860e041050b337beb1bc81d46db38652aeea965..a8a8af0e6c355e3bc65a00a53472685678d8260c 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/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
index 64f0eaac1bd4053b87f1e6dcbb44c0e7e724cfa5..7523c8be0670b9f4a3df79a1aaf7e5a572ef748a 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 49d08333ef4cecd2d9e5161e6b0298895527cfc9..ef46b7963af3a6bdec054fa53536516877435fc7 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 7f249d9bea14190869d6e59a86fd1bd85a11cfd7..f811c16c15d82829d02f7d6642bfe5793abf7560 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 6bfc6cb0d2f71bcf29dfe376ee43bd6a1454060e..ba1757ffc5ee8825856c69a6a05c0e944f09a564 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 db78cd9458a5be0465458f09c48248e533935367..d185219c9a2ae898cc6d65afff378af536a915e6 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/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php b/core/tests/Drupal/Tests/Core/Entity/Access/EntityFormDisplayAccessControlHandlerTest.php
index 1ee804d5398a53f8d72b85cc9de30a02d5479f8c..a92d76abb70d585c2d2db84bb278b15e567f95f2 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 ad68e2df68e4ed5e60fc07434fe0152ae329d8d2..55928b98a6e226ca2040c9f3f499d42e60c5d29f 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 4a2dac5653e00c1e4761f755ef116443a9427956..846ce0a59f2f1305f4fe21808fc2952c2d3988be 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/Core/Listeners/DrupalStandardsListenerDeprecationTest.php b/core/tests/Drupal/Tests/Core/Listeners/DrupalStandardsListenerDeprecationTest.php
index 61b62118af1467755ac11ba4d18d9104386a02de..ad3930440b891f466361230e32a0dc1d829f0c37 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 2512602afaf20ba47726c449b92030031f939fd3..0f934ebf8e6727fcba884e8b165885ce7c6b5028 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 929930a5216b49fee6f6bb398da971f439531b73..e6215caac834e310a794ea5bc605447c60244aaf 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 2190d5391878a071362afe8e3e1b781fb0c0d165..7dead3d32e230afe92145ffa451adcc8127c569c 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 1fca8179a8327601bb650bd6a76e8583a4f59c58..a881e7c2ce7240a904714741b10ae58e2a031a37 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/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
index 5cf020a8df6b999663a06aa624779f200eea6f46..ee14f005a6f8681f93802d7bf1bb858f49acffed 100644
--- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
+++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
@@ -116,6 +116,31 @@ public function createMock($originalClassName) {
     }
   }
 
+  /**
+   * Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
+   *
+   * @param mixed $class
+   *   The expected exception class.
+   * @param string $message
+   *   The expected exception message.
+   * @param int $exception_code
+   *   The expected 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);
+    }
+  }
+
   /**
    * Checks if the trait is used in a class that has a method.
    *
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index f78b69ff0498f2c99ae1e1b0d790261e589c8e6f..50fef61ee6851e33731996b10b40c57283ad802d 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -8,6 +8,7 @@
  */
 
 use Drupal\Component\Assertion\Handle;
+use PHPUnit\Runner\Version;
 
 /**
  * Finds all valid extension directories recursively within a given directory.
@@ -166,3 +167,19 @@ function drupal_phpunit_populate_class_loader() {
 // make PHP 5 and 7 handle assertion failures the same way, but this call does
 // not turn runtime assertions on if they weren't on already.
 Handle::register();
+
+// PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on
+// PHPUnit 6 with a minimum of fuss.
+if (class_exists('PHPUnit\Runner\Version') && version_compare(Version::id(), '6.1', '>=')) {
+  class_alias('\PHPUnit\Framework\AssertionFailedError', '\PHPUnit_Framework_AssertionFailedError');
+  class_alias('\PHPUnit\Framework\Constraint\Count', '\PHPUnit_Framework_Constraint_Count');
+  class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error');
+  class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning');
+  class_alias('\PHPUnit\Framework\ExpectationFailedException', '\PHPUnit_Framework_ExpectationFailedException');
+  class_alias('\PHPUnit\Framework\Exception', '\PHPUnit_Framework_Exception');
+  class_alias('\PHPUnit\Framework\MockObject\Matcher\InvokedRecorder', '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder');
+  class_alias('\PHPUnit\Framework\SkippedTestError', '\PHPUnit_Framework_SkippedTestError');
+  class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
+  class_alias('\PHPUnit\Util\Test', '\PHPUnit_Util_Test');
+  class_alias('\PHPUnit\Util\XML', '\PHPUnit_Util_XML');
+}