From 50a6a9efc1c4742d1834ad16fcd556dbe508fbfc Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 23 Aug 2019 10:05:21 +0100
Subject: [PATCH] Issue #3060391 by mondrake, Mile23, Lendude, alexpott:
 Cleanup usage of PHPUnit 4.8 aliased classes

---
 core/lib/Drupal/Core/Test/TestDiscovery.php   |  8 +-
 .../AggregatorPluginSettingsBaseTest.php      |  4 +-
 .../tests/src/Kernel/DateTimeItemTest.php     |  5 +-
 .../image/tests/src/Kernel/ImageItemTest.php  |  3 +-
 .../tests/src/Unit/LocaleLookupTest.php       |  2 +-
 .../tests/fixtures/phpunit_error.xml          |  8 +-
 .../src/Functional/Menu/BreadcrumbTest.php    |  7 +-
 .../tests/src/Kernel/ViewExecutableTest.php   |  3 +-
 core/scripts/run-tests.sh                     |  9 --
 .../BrowserWithJavascriptTest.php             |  3 +-
 .../WebDriverTestBase.php                     |  2 +-
 .../FunctionalTests/BrowserTestBaseTest.php   | 19 ++--
 .../Core/Config/ConfigInstallTest.php         |  3 +-
 .../Core/Test/BrowserTestBaseTest.php         |  5 +-
 .../Drupal/KernelTests/KernelTestBase.php     |  5 +-
 .../Drupal/KernelTests/KernelTestBaseTest.php |  5 +-
 .../Component/Diff/Engine/DiffOpTest.php      |  7 +-
 .../Tests/Component/DrupalComponentTest.php   |  3 +-
 .../Component/PhpStorage/FileStorageTest.php  | 10 +--
 .../Core/Assert/AssertLegacyTraitTest.php     | 12 +--
 .../Drupal/Tests/Core/Config/ConfigTest.php   |  3 +-
 .../Tests/Core/Database/ConditionTest.php     |  3 +-
 .../RedirectResponseSubscriberTest.php        |  5 +-
 .../SpecialAttributesRouteSubscriberTest.php  |  3 +-
 .../Core/Menu/ContextualLinkManagerTest.php   |  3 +-
 .../Core/PathProcessor/PathProcessorTest.php  |  2 +-
 .../DefaultSingleLazyPluginCollectionTest.php |  3 +-
 .../Plugin/LazyPluginCollectionTestBase.php   |  5 +-
 .../Drupal/Tests/Core/Render/ElementTest.php  |  3 +-
 .../Core/Render/RendererPlaceholdersTest.php  |  2 +-
 .../StringTranslationTraitTest.php            |  2 +-
 core/tests/Drupal/Tests/Core/UrlTest.php      |  2 +-
 .../Tests/Listeners/AfterSymfonyListener.php  | 33 +++----
 .../Listeners/DeprecationListenerTrait.php    | 10 +--
 .../DrupalComponentTestListenerTrait.php      |  2 +-
 .../Drupal/Tests/Listeners/DrupalListener.php | 55 +++++-------
 .../DrupalStandardsListenerTrait.php          | 15 ++--
 .../Tests/Listeners/HtmlOutputPrinter.php     | 49 +++++-----
 .../Listeners/Legacy/AfterSymfonyListener.php | 19 ----
 .../Tests/Listeners/Legacy/DrupalListener.php | 36 --------
 .../Listeners/Legacy/HtmlOutputPrinter.php    | 33 -------
 .../Tests/Phpunit4CompatibilityTest.php       | 89 +++++++++++++++++++
 .../Tests/PhpunitCompatibilityTrait.php       |  1 -
 .../Drupal/Tests/TestRequirementsTrait.php    | 13 +--
 .../Tests/Traits/ExpectDeprecationTrait.php   | 18 ++--
 core/tests/Drupal/Tests/UnitTestCase.php      |  2 +-
 core/tests/bootstrap.php                      | 45 +++++-----
 47 files changed, 272 insertions(+), 307 deletions(-)
 delete mode 100644 core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php
 delete mode 100644 core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php
 delete mode 100644 core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php
 create mode 100644 core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php

diff --git a/core/lib/Drupal/Core/Test/TestDiscovery.php b/core/lib/Drupal/Core/Test/TestDiscovery.php
index a8374f92a225..7bb08ac4a316 100644
--- a/core/lib/Drupal/Core/Test/TestDiscovery.php
+++ b/core/lib/Drupal/Core/Test/TestDiscovery.php
@@ -7,7 +7,7 @@
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Extension\ExtensionDiscovery;
 use Drupal\Core\Test\Exception\MissingGroupException;
-use PHPUnit_Util_Test;
+use PHPUnit\Util\Test;
 
 /**
  * Discovers available tests.
@@ -418,14 +418,14 @@ public static function parseTestClassSummary($doc_comment) {
    *     - module: A list of Drupal module dependencies that are required to
    *       exist.
    *
-   * @see PHPUnit_Util_Test::parseTestMethodAnnotations()
+   * @see \PHPUnit\Util\Test::parseTestMethodAnnotations()
    * @see http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires
    */
   public static function parseTestClassAnnotations(\ReflectionClass $class) {
-    $annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class->getName())['class'];
+    $annotations = Test::parseTestMethodAnnotations($class->getName())['class'];
 
     // @todo Enhance PHPUnit upstream to allow for custom @requires identifiers.
-    // @see PHPUnit_Util_Test::getRequirements()
+    // @see \PHPUnit\Util\Test::getRequirements()
     // @todo Add support for 'PHP', 'OS', 'function', 'extension'.
     // @see https://www.drupal.org/node/1273478
     if (isset($annotations['requires'])) {
diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
index 51525b9814fc..a6918a2127ff 100644
--- a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
+++ b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
@@ -24,7 +24,7 @@ class AggregatorPluginSettingsBaseTest extends UnitTestCase {
   /**
    * The stubbed config factory object.
    *
-   * @var \PHPUnit_Framework_MockObject_MockBuilder
+   * @var \PHPUnit\Framework\MockObject\MockBuilder
    */
   protected $configFactory;
 
@@ -56,7 +56,7 @@ protected function setUp() {
         ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']]));
     }
 
-    /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockBuilder $messenger */
+    /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockBuilder $messenger */
     $messenger = $this->createMock(MessengerInterface::class);
     $messenger->expects($this->any())->method('addMessage');
 
diff --git a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
index 7c1ca1ef9b7b..03fc213e9d4a 100644
--- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
+++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php
@@ -10,6 +10,7 @@
 use Drupal\field\Entity\FieldConfig;
 use Drupal\Tests\field\Kernel\FieldKernelTestBase;
 use Drupal\field\Entity\FieldStorageConfig;
+use PHPUnit\Framework\AssertionFailedError;
 
 /**
  * Tests the new entity API for the date field type.
@@ -255,7 +256,7 @@ public function testSetValueProperty() {
    * @dataProvider datetimeValidationProvider
    */
   public function testDatetimeValidation($value) {
-    $this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
+    $this->expectException(AssertionFailedError::class);
 
     $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME);
     $this->fieldStorage->save();
@@ -315,7 +316,7 @@ public function datetimeValidationProvider() {
    * @dataProvider dateonlyValidationProvider
    */
   public function testDateonlyValidation($value) {
-    $this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
+    $this->expectException(AssertionFailedError::class);
 
     $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE);
     $this->fieldStorage->save();
diff --git a/core/modules/image/tests/src/Kernel/ImageItemTest.php b/core/modules/image/tests/src/Kernel/ImageItemTest.php
index bd2c53460d93..5f095bb8a818 100644
--- a/core/modules/image/tests/src/Kernel/ImageItemTest.php
+++ b/core/modules/image/tests/src/Kernel/ImageItemTest.php
@@ -12,6 +12,7 @@
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\file\Entity\File;
 use Drupal\user\Entity\Role;
+use PHPUnit\Framework\Error\Warning;
 
 /**
  * Tests using entity fields of the image field type.
@@ -153,7 +154,7 @@ public function testImageItemMalformed() {
       $this->fail('Exception did not fail');
     }
     catch (EntityStorageException $exception) {
-      $this->assertInstanceOf(\PHPUnit_Framework_Error_Warning::class, $exception->getPrevious());
+      $this->assertInstanceOf(Warning::class, $exception->getPrevious());
       $this->assertEquals($exception->getMessage(), 'Missing file with ID 9999.');
       $this->assertEmpty($entity->image_test->width);
       $this->assertEmpty($entity->image_test->height);
diff --git a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
index e386de3a48c4..639e812bd3b8 100644
--- a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
+++ b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
@@ -46,7 +46,7 @@ class LocaleLookupTest extends UnitTestCase {
   /**
    * A mocked config factory built with UnitTestCase::getConfigFactoryStub().
    *
-   * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockBuilder
+   * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit\Framework\MockObject\MockBuilder
    */
   protected $configFactory;
 
diff --git a/core/modules/simpletest/tests/fixtures/phpunit_error.xml b/core/modules/simpletest/tests/fixtures/phpunit_error.xml
index 82386aea74c1..6a6a1cbc20f2 100644
--- a/core/modules/simpletest/tests/fixtures/phpunit_error.xml
+++ b/core/modules/simpletest/tests/fixtures/phpunit_error.xml
@@ -7,7 +7,7 @@
     <testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/>
     <testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680">
       <testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680">
-        <error type="PHPUnit_Framework_Error_Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude
+        <error type="PHPUnit\Framework\Error\Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude
 Undefined index: foo
 
 /home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219
@@ -20,19 +20,19 @@ Undefined index: foo
     <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestkTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
       <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176">
         <testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519">
-          <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
+          <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
             Access granted for user with the roles role_test_1 on path: role_test_1
             Failed asserting that false is true.
           </failure>
         </testcase>
         <testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354">
-          <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
+          <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User))
             Access granted for user with the roles role_test_2 on path: role_test_2
             Failed asserting that false is true.
           </failure>
         </testcase>
         <testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303">
-          <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User))
+          <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User))
             Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3
             Failed asserting that false is true.
           </failure>
diff --git a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
index 329a5f9c2d33..5c873477925a 100644
--- a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
+++ b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
@@ -7,6 +7,7 @@
 use Drupal\node\Entity\NodeType;
 use Drupal\Tests\BrowserTestBase;
 use Drupal\user\RoleInterface;
+use PHPUnit\Framework\ExpectationFailedException;
 
 /**
  * Tests breadcrumbs functionality.
@@ -399,7 +400,7 @@ public function testAssertBreadcrumbTrait() {
       $this->assertBreadcrumb('menu-test/breadcrumb1', []);
       $this->fail($message);
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->assertTrue(TRUE, $message);
     }
 
@@ -409,7 +410,7 @@ public function testAssertBreadcrumbTrait() {
       $this->assertBreadcrumb('menu-test/breadcrumb1', $home);
       $this->fail($message);
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->assertTrue(TRUE, $message);
     }
 
@@ -426,7 +427,7 @@ public function testAssertBreadcrumbTrait() {
       $this->assertBreadcrumb('menu-test/breadcrumb1', $trail);
       $this->fail($message);
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->assertTrue(TRUE, $message);
     }
   }
diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
index d120856c0fdb..e59dc8defedb 100644
--- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
+++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
@@ -20,6 +20,7 @@
 use Drupal\views\Plugin\views\pager\PagerPluginBase;
 use Drupal\views\Plugin\views\query\QueryPluginBase;
 use Drupal\views_test_data\Plugin\views\display\DisplayTest;
+use PHPUnit\Framework\Error\Warning;
 use Symfony\Component\HttpFoundation\Response;
 
 /**
@@ -201,7 +202,7 @@ public function testSetDisplayWithInvalidDisplay() {
       $view->setDisplay('invalid');
       $this->fail('Expected error, when setDisplay() called with invalid display ID');
     }
-    catch (\PHPUnit_Framework_Error_Warning $e) {
+    catch (Warning $e) {
       $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage());
     }
 
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index a3e94a42582b..26763c3adbe0 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -20,7 +20,6 @@
 use Drupal\simpletest\Form\SimpletestResultsForm;
 use Drupal\Core\Test\TestDiscovery;
 use PHPUnit\Framework\TestCase;
-use PHPUnit\Runner\Version;
 use Symfony\Component\HttpFoundation\Request;
 
 // Define some colors for display.
@@ -144,14 +143,6 @@
   exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS);
 }
 
-// Ensure we have the correct PHPUnit version for the version of PHP.
-if (class_exists('\PHPUnit_Runner_Version')) {
-  $phpunit_version = \PHPUnit_Runner_Version::id();
-}
-else {
-  $phpunit_version = Version::id();
-}
-
 $test_list = simpletest_script_get_test_list();
 
 // Try to allocate unlimited time to run the tests.
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
index 4532880f59d0..76454f741c76 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\FunctionalJavascriptTests;
 
 use Behat\Mink\Driver\GoutteDriver;
+use PHPUnit\Framework\AssertionFailedError;
 
 /**
  * Tests if we can execute JavaScript in the browser.
@@ -56,7 +57,7 @@ public function testAssertJsCondition() {
 
     // We expected the following assertion to fail because the window has been
     // re-sized to have a width of 500 not 400.
-    $this->expectException(\PHPUnit_Framework_AssertionFailedError::class);
+    $this->expectException(AssertionFailedError::class);
     $this->assertJsCondition($javascript, 100);
   }
 
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
index 38167417ae69..d677aa8e2d64 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
@@ -168,7 +168,7 @@ protected function assertElementNotVisible($css_selector, $message = '') {
    *   (optional) A message to display with the assertion. If left blank, a
    *   default message will be displayed.
    *
-   * @throws \PHPUnit_Framework_AssertionFailedError
+   * @throws \PHPUnit\Framework\AssertionFailedError
    *
    * @see \Behat\Mink\Driver\DriverInterface::evaluateScript()
    */
diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
index f562d4d94092..3a94bddd76e6 100644
--- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Url;
 use Drupal\Tests\BrowserTestBase;
 use Drupal\Tests\Traits\Core\CronRunTrait;
+use PHPUnit\Framework\ExpectationFailedException;
 
 /**
  * Tests BrowserTestBase functionality.
@@ -263,7 +264,7 @@ public function testXpathAsserts() {
       $this->assertFieldByXPath("//input[@id = 'notexisting']");
       $this->fail('The "notexisting" field was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.');
     }
 
@@ -279,7 +280,7 @@ public function testXpathAsserts() {
       $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value');
       $this->fail('The "edit-name" field is found with the value "not the value".');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('The "edit-name" field is not found with the value "not the value".');
     }
   }
@@ -320,7 +321,7 @@ public function testFieldAssertsForTextfields() {
       $this->assertField('invalid_name_and_id');
       $this->fail('The "invalid_name_and_id" field was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
     }
 
@@ -359,7 +360,7 @@ public function testFieldAssertsForTextfields() {
       $this->assertFieldById('edit-name');
       $this->fail('The "edit-name" field with no value was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('The "edit-name" field with no value was not found.');
     }
 
@@ -368,7 +369,7 @@ public function testFieldAssertsForTextfields() {
       $this->assertFieldById('edit-name', 'not the value');
       $this->fail('The "name" field was found, using the wrong value.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('The "name" field was not found, using the wrong value.');
     }
 
@@ -409,7 +410,7 @@ public function testFieldAssertsForTextfields() {
       $this->assertFieldByName('non-existing-name');
       $this->fail('The "non-existing-name" field was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('The "non-existing-name" field was not found');
     }
 
@@ -418,7 +419,7 @@ public function testFieldAssertsForTextfields() {
       $this->assertFieldByName('name', 'not the value');
       $this->fail('The "name" field with incorrect value was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
     }
 
@@ -473,7 +474,7 @@ public function testFieldAssertsForOptions() {
       $this->assertOptionSelected('options', 1);
       $this->fail('The select option "1" was selected.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass($e->getMessage());
     }
 
@@ -492,7 +493,7 @@ public function testFieldAssertsForButton() {
       $this->assertFieldById('Save', NULL);
       $this->fail('The field with id of "Save" was found.');
     }
-    catch (\PHPUnit_Framework_ExpectationFailedException $e) {
+    catch (ExpectationFailedException $e) {
       $this->pass($e->getMessage());
     }
 
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php
index a8d0f6601830..c5cee5720361 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Config\PreExistingConfigException;
 use Drupal\Core\Config\UnmetDependenciesException;
 use Drupal\KernelTests\KernelTestBase;
+use PHPUnit\Framework\Error\Warning;
 
 /**
  * Tests installation of configuration objects in installation functionality.
@@ -257,7 +258,7 @@ public function testLanguage() {
    * Tests installing configuration where the filename and ID do not match.
    */
   public function testIdMisMatch() {
-    $this->expectException(\PHPUnit_Framework_Error_Warning::class);
+    $this->expectException(Warning::class);
     $this->expectExceptionMessage('The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"');
     $this->installModules(['config_test_id_mismatch']);
   }
diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
index c93069c8e404..83631e5df372 100644
--- a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
@@ -5,6 +5,7 @@
 use Drupal\FunctionalTests\BrowserMissingDependentModuleMethodTest;
 use Drupal\FunctionalTests\BrowserMissingDependentModuleTest;
 use Drupal\KernelTests\KernelTestBase;
+use PHPUnit\Framework\SkippedTestError;
 
 /**
  * @group Test
@@ -36,7 +37,7 @@ public function testMethodRequiresModule() {
       $stub_test->publicCheckRequirements();
       $this->fail('Missing required module throws skipped test exception.');
     }
-    catch (\PHPUnit_Framework_SkippedTestError $e) {
+    catch (SkippedTestError $e) {
       $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
     }
   }
@@ -63,7 +64,7 @@ public function testRequiresModule() {
       $stub_test->publicCheckRequirements();
       $this->fail('Missing required module throws skipped test exception.');
     }
-    catch (\PHPUnit_Framework_SkippedTestError $e) {
+    catch (SkippedTestError $e) {
       $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
     }
   }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index f89aa4d9b00e..e2d1c17f3bf7 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -22,6 +22,7 @@
 use Drupal\Tests\PhpunitCompatibilityTrait;
 use Drupal\Tests\RandomGeneratorTrait;
 use Drupal\Tests\TestRequirementsTrait;
+use PHPUnit\Framework\Exception;
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\HttpFoundation\Request;
@@ -477,7 +478,7 @@ protected function initFileCache() {
    * @return \Drupal\Core\Extension\Extension[]
    *   Extension objects for $modules, keyed by module name.
    *
-   * @throws \PHPUnit_Framework_Exception
+   * @throws \PHPUnit\Framework\Exception
    *   If a module is not available.
    *
    * @see \Drupal\Tests\KernelTestBase::enableModules()
@@ -490,7 +491,7 @@ private function getExtensionsForModules(array $modules) {
     $list = $discovery->scan('module');
     foreach ($modules as $name) {
       if (!isset($list[$name])) {
-        throw new \PHPUnit_Framework_Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
+        throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
       }
       $extensions[$name] = $list[$name];
     }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index 05037bb208ad..426fa8bb2701 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Database\Database;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
+use PHPUnit\Framework\SkippedTestError;
 
 /**
  * @coversDefaultClass \Drupal\KernelTests\KernelTestBase
@@ -249,7 +250,7 @@ public function testMethodRequiresModule() {
       $stub_test->publicCheckRequirements();
       $this->fail('Missing required module throws skipped test exception.');
     }
-    catch (\PHPUnit_Framework_SkippedTestError $e) {
+    catch (SkippedTestError $e) {
       $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
     }
   }
@@ -276,7 +277,7 @@ public function testRequiresModule() {
       $stub_test->publicCheckRequirements();
       $this->fail('Missing required module throws skipped test exception.');
     }
-    catch (\PHPUnit_Framework_SkippedTestError $e) {
+    catch (SkippedTestError $e) {
       $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
     }
   }
diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
index f7f17f39c6fa..be2054811ea9 100644
--- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
+++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php
@@ -25,12 +25,7 @@ class DiffOpTest extends TestCase {
    * @covers ::reverse
    */
   public function testReverse() {
-    if (method_exists($this, 'expectException')) {
-      $this->expectException(Error::class);
-    }
-    else {
-      $this->expectException(\PHPUnit_Framework_Error::class);
-    }
+    $this->expectException(Error::class);
     $op = new DiffOp();
     $result = $op->reverse();
   }
diff --git a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
index 6b08cd94eb49..6f9d149a9b44 100644
--- a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
+++ b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Component;
 
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\AssertionFailedError;
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -144,7 +145,7 @@ public function testAssertNoCoreUseage($expected_pass, $file_data) {
       $pass = TRUE;
       $this->assertNoCoreUsage($file_uri);
     }
-    catch (\PHPUnit_Framework_AssertionFailedError $e) {
+    catch (AssertionFailedError $e) {
       $pass = FALSE;
     }
     $this->assertEquals($expected_pass, $pass, $expected_pass ?
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
index 357f4e05f4ea..891a1dcceb9a 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
@@ -99,14 +99,8 @@ public function testCreateDirectoryFailWarning() {
       'bin' => 'test',
     ]);
     $code = "<?php\n echo 'here';";
-    if (method_exists($this, 'expectException')) {
-      $this->expectException(Warning::class);
-      $this->expectExceptionMessage('mkdir(): Permission Denied');
-    }
-    else {
-      $this->expectException(\PHPUnit_Framework_Error_Warning::class);
-      $this->expectExceptionMessage('mkdir(): Permission Denied');
-    }
+    $this->expectException(Warning::class);
+    $this->expectExceptionMessage('mkdir(): Permission Denied');
     $storage->save('subdirectory/foo.php', $code);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
index ec01d4e26f96..b86565280994 100644
--- a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@@ -9,7 +9,7 @@
 use Drupal\FunctionalTests\AssertLegacyTrait;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Tests\WebAssert;
-use PHPUnit_Framework_ExpectationFailedException;
+use PHPUnit\Framework\ExpectationFailedException;
 
 /**
  * @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait
@@ -66,7 +66,7 @@ public function testAssertUniqueText() {
    */
   public function testAssertUniqueTextFail() {
     $this->page->getText()->willReturn('foo bar bar');
-    $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
+    $this->expectException(ExpectationFailedException::class);
     $this->assertUniqueText('bar');
   }
 
@@ -75,7 +75,7 @@ public function testAssertUniqueTextFail() {
    */
   public function testAssertUniqueTextUnknown() {
     $this->page->getText()->willReturn('foo bar bar');
-    $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
+    $this->expectException(ExpectationFailedException::class);
     $this->assertUniqueText('alice');
   }
 
@@ -102,7 +102,7 @@ public function testAssertNoUniqueText() {
    */
   public function testAssertNoUniqueTextFail() {
     $this->page->getText()->willReturn('foo bar bar');
-    $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
+    $this->expectException(ExpectationFailedException::class);
     $this->assertNoUniqueText('foo');
   }
 
@@ -111,7 +111,7 @@ public function testAssertNoUniqueTextFail() {
    */
   public function testAssertNoUniqueTextUnknown() {
     $this->page->getText()->willReturn('foo bar bar');
-    $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
+    $this->expectException(ExpectationFailedException::class);
     $this->assertNoUniqueText('alice');
   }
 
@@ -150,7 +150,7 @@ public function testAssertOptionSelectedFail() {
       ->optionExists('myselect', 'two')
       ->willReturn($option_field->reveal());
 
-    $this->expectException(PHPUnit_Framework_ExpectationFailedException::class);
+    $this->expectException(ExpectationFailedException::class);
     $this->assertOptionSelected('myselect', 'two');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
index fb620f4ade0d..a59ebf5e76ce 100644
--- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
@@ -7,6 +7,7 @@
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Config\Config;
 use Drupal\Core\Config\ConfigValueException;
+use PHPUnit\Framework\Error\Warning;
 
 /**
  * Tests the Config.
@@ -269,7 +270,7 @@ public function testSetIllegalOffsetValue() {
     $this->config->set('testData', 1);
 
     // Attempt to treat the single value as a nested item.
-    $this->expectException(\PHPUnit_Framework_Error_Warning::class);
+    $this->expectException(Warning::class);
     $this->config->set('testData.illegalOffset', 1);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
index 29a5aabfa85a..c38261b86626 100644
--- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
+++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
@@ -7,6 +7,7 @@
 use Drupal\Core\Database\Query\PlaceholderInterface;
 use Drupal\Tests\UnitTestCase;
 use Prophecy\Argument;
+use PHPUnit\Framework\Error\Error;
 
 /**
  * @coversDefaultClass \Drupal\Core\Database\Query\Condition
@@ -161,7 +162,7 @@ public function testCompileWithSqlInjectionForOperator($operator) {
 
     $condition = new Condition('AND');
     $condition->condition('name', 'value', $operator);
-    $this->expectException(\PHPUnit_Framework_Error::class);
+    $this->expectException(Error::class);
     $condition->compile($connection, $query_placeholder);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
index 2c582d0c123a..ac06bbf266fa 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Routing\TrustedRedirectResponse;
 use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
 use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\Error\Error;
 use Symfony\Component\DependencyInjection\Container;
 use Symfony\Component\EventDispatcher\EventDispatcher;
 use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -123,7 +124,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
-    $this->expectException(\PHPUnit_Framework_Error::class);
+    $this->expectException(Error::class);
     $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
   }
 
@@ -171,7 +172,7 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
-    $this->expectException(\PHPUnit_Framework_Error::class);
+    $this->expectException(Error::class);
     $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
index aee20d08b3fa..0aa466bddc48 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
@@ -5,6 +5,7 @@
 use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber;
 use Drupal\Core\Routing\RouteBuildEvent;
 use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\Error\Warning;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\Routing\Route;
 use Symfony\Component\Routing\RouteCollection;
@@ -98,7 +99,7 @@ public function testOnRouteBuildingInvalidVariables(Route $route) {
 
     $event = new RouteBuildEvent($route_collection, 'test');
     $subscriber = new SpecialAttributesRouteSubscriber();
-    $this->expectException(\PHPUnit_Framework_Error_Warning::class);
+    $this->expectException(Warning::class);
     $this->expectExceptionMessage('uses reserved variable names');
     $subscriber->onAlterRoutes($event);
   }
diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
index bb5e98ee9074..c146c04c4f9d 100644
--- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
@@ -7,6 +7,7 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Menu\ContextualLinkDefault;
 use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\Constraint\Count;
 use Symfony\Component\HttpFoundation\RequestStack;
 
 /**
@@ -286,7 +287,7 @@ public function testGetContextualLinksArrayByGroup() {
 
     $this->moduleHandler->expects($this->at(1))
       ->method('alter')
-      ->with($this->equalTo('contextual_links'), new \PHPUnit_Framework_Constraint_Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value']));
+      ->with($this->equalTo('contextual_links'), new Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value']));
 
     $result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', ['key' => 'value']);
     $this->assertCount(2, $result);
diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
index 0aa2de7b64bc..ce401b125576 100644
--- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
@@ -31,7 +31,7 @@ class PathProcessorTest extends UnitTestCase {
   /**
    * The language manager stub used to construct a PathProcessorLanguage object.
    *
-   * @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit_Framework_MockObject_MockBuilder
+   * @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit\Framework\MockObject\MockBuilder
    */
   protected $languageManager;
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
index cd8b384614b5..807c33ed74d1 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php
@@ -5,6 +5,7 @@
 use Drupal\Component\Plugin\ConfigurableInterface;
 use Drupal\Component\Plugin\PluginBase;
 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
+use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
 
 /**
  * @coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
@@ -15,7 +16,7 @@ class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase
   /**
    * {@inheritdoc}
    */
-  protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) {
+  protected function setupPluginCollection(InvokedRecorder $create_count = NULL) {
     $definitions = $this->getPluginDefinitions();
     $this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']);
     $this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']);
diff --git a/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php b/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php
index 0e103688b417..5337468da1c2 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Plugin\DefaultLazyPluginCollection;
 use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
 
 /**
  * Provides a base class for plugin collection tests.
@@ -53,12 +54,12 @@ protected function setUp() {
   /**
    * Sets up the default plugin collection.
    *
-   * @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|null $create_count
+   * @param \PHPUnit\Framework\MockObject\Matcher\InvokedRecorder|null $create_count
    *   (optional) The number of times that createInstance() is expected to be
    *   called. For example, $this->any(), $this->once(), $this->exactly(6).
    *   Defaults to $this->never().
    */
-  protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) {
+  protected function setupPluginCollection(InvokedRecorder $create_count = NULL) {
     $this->pluginInstances = [];
     $map = [];
     foreach ($this->getPluginDefinitions() as $plugin_id => $definition) {
diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
index 9d4342d1d731..f12dfcf1dd65 100644
--- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
@@ -5,6 +5,7 @@
 use Drupal\Core\Access\AccessResult;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Render\Element;
+use PHPUnit\Framework\Error\Error;
 
 /**
  * @coversDefaultClass \Drupal\Core\Render\Element
@@ -106,7 +107,7 @@ public function testInvalidChildren() {
     $element = [
       'foo' => 'bar',
     ];
-    $this->expectException(\PHPUnit_Framework_Error::class);
+    $this->expectException(Error::class);
     $this->expectExceptionMessage('"foo" is an invalid render array key');
     Element::children($element);
   }
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
index 77a2024dddfa..6e56588f25d7 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@@ -1118,7 +1118,7 @@ protected function generatePlaceholdersWithChildrenTestElement(array $args_1, ar
   }
 
   /**
-   * @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_Builder_InvocationMocker
+   * @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit\Framework\MockObject\Builder\InvocationMocker
    */
   protected function setupThemeManagerForDetails() {
     return $this->themeManager->expects($this->any())
diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php
index 560675eed883..5e16fa88e6d5 100644
--- a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php
@@ -25,7 +25,7 @@ class StringTranslationTraitTest extends UnitTestCase {
    * The mock under test that uses StringTranslationTrait.
    *
    * @var object
-   * @see PHPUnit_Framework_MockObject_Generator::getObjectForTrait()
+   * @see \PHPUnit\Framework\MockObject\Generator::getObjectForTrait()
    */
   protected $translation;
 
diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php
index dcdee870a1e0..58dbdbd8332d 100644
--- a/core/tests/Drupal/Tests/Core/UrlTest.php
+++ b/core/tests/Drupal/Tests/Core/UrlTest.php
@@ -160,7 +160,7 @@ public function testUrlFromRequest() {
    * @param string $path
    *   The path.
    *
-   * @return \PHPUnit_Framework_Constraint_Callback
+   * @return \PHPUnit\Framework\Constraint\Callback
    *   The constraint checks whether a Request object has the right path.
    */
   protected function getRequestConstraint($path) {
diff --git a/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php b/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php
index 121d0d2db246..8806decd1cd0 100644
--- a/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php
+++ b/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php
@@ -6,28 +6,19 @@
 use PHPUnit\Framework\TestListener;
 use PHPUnit\Framework\TestListenerDefaultImplementation;
 
-if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
-  class_alias('Drupal\Tests\Listeners\Legacy\AfterSymfonyListener', 'Drupal\Tests\Listeners\AfterSymfonyListener');
-  // Using an early return instead of an else does not work when using the
-  // PHPUnit phar due to some weird PHP behavior (the class gets defined without
-  // executing the code before it and so the definition is not properly
-  // conditional).
-}
-else {
+/**
+ * Listens to PHPUnit test runs.
+ *
+ * @internal
+ */
+class AfterSymfonyListener implements TestListener {
+  use TestListenerDefaultImplementation;
+
   /**
-   * Listens to PHPUnit test runs.
-   *
-   * @internal
+   * {@inheritdoc}
    */
-  class AfterSymfonyListener implements TestListener {
-    use TestListenerDefaultImplementation;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function endTest(Test $test, $time) {
-      restore_error_handler();
-    }
-
+  public function endTest(Test $test, $time) {
+    restore_error_handler();
   }
+
 }
diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
index f26d333cfc06..3c76756bd5fb 100644
--- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -4,6 +4,7 @@
 
 use Drupal\Tests\Traits\ExpectDeprecationTrait;
 use PHPUnit\Framework\TestCase;
+use PHPUnit\Util\Test;
 
 /**
  * Removes deprecations that we are yet to fix.
@@ -24,7 +25,7 @@ trait DeprecationListenerTrait {
   private $previousHandler;
 
   protected function deprecationStartTest($test) {
-    if ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase) {
+    if ($test instanceof TestCase) {
       if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
         $this->registerErrorHandler($test);
       }
@@ -37,7 +38,7 @@ protected function deprecationStartTest($test) {
   /**
    * Reacts to the end of a test.
    *
-   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   * @param \PHPUnit\Framework\Test $test
    *   The test object that has ended its test run.
    * @param float $time
    *   The time the test took.
@@ -52,13 +53,12 @@ protected function deprecationEndTest($test, $time) {
       }
     }
     if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
-      $util_test_class = class_exists('PHPUnit_Util_Test') ? 'PHPUnit_Util_Test' : 'PHPUnit\Util\Test';
       $method = $test->getName(FALSE);
       if (strpos($method, 'testLegacy') === 0
         || strpos($method, 'provideLegacy') === 0
         || strpos($method, 'getLegacy') === 0
         || strpos(get_class($test), '\Legacy')
-        || in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) {
+        || in_array('legacy', Test::getGroups(get_class($test), $method), TRUE)) {
         // This is a legacy test don't skip deprecations.
         return;
       }
@@ -83,7 +83,7 @@ protected function deprecationEndTest($test, $time) {
   /**
    * Determines if a test is isolated.
    *
-   * @param \PHPUnit_Framework_TestCase|\PHPUnit\Framework\TestCase $test
+   * @param \PHPUnit\Framework\TestCase $test
    *   The test to check.
    *
    * @return bool
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php
index 105d1333c345..6428bae39c0e 100644
--- a/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php
@@ -17,7 +17,7 @@ trait DrupalComponentTestListenerTrait {
   /**
    * Reacts to the end of a test.
    *
-   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   * @param \PHPUnit\Framework\Test $test
    *   The test object that has ended its test run.
    * @param float $time
    *   The time the test took.
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/DrupalListener.php
index 3d410ce5585e..8b7966a26d65 100644
--- a/core/tests/Drupal/Tests/Listeners/DrupalListener.php
+++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php
@@ -6,40 +6,31 @@
 use PHPUnit\Framework\TestListener;
 use PHPUnit\Framework\TestListenerDefaultImplementation;
 
-if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
-  class_alias('Drupal\Tests\Listeners\Legacy\DrupalListener', 'Drupal\Tests\Listeners\DrupalListener');
-  // Using an early return instead of a else does not work when using the
-  // PHPUnit phar due to some weird PHP behavior (the class gets defined without
-  // executing the code before it and so the definition is not properly
-  // conditional).
-}
-else {
+/**
+ * Listens to PHPUnit test runs.
+ *
+ * @internal
+ */
+class DrupalListener implements TestListener {
+  use TestListenerDefaultImplementation;
+  use DeprecationListenerTrait;
+  use DrupalComponentTestListenerTrait;
+  use DrupalStandardsListenerTrait;
+
   /**
-   * Listens to PHPUnit test runs.
-   *
-   * @internal
+   * {@inheritdoc}
    */
-  class DrupalListener implements TestListener {
-    use TestListenerDefaultImplementation;
-    use DeprecationListenerTrait;
-    use DrupalComponentTestListenerTrait;
-    use DrupalStandardsListenerTrait;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function startTest(Test $test) {
-      $this->deprecationStartTest($test);
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function endTest(Test $test, $time) {
-      $this->deprecationEndTest($test, $time);
-      $this->componentEndTest($test, $time);
-      $this->standardsEndTest($test, $time);
-    }
+  public function startTest(Test $test) {
+    $this->deprecationStartTest($test);
+  }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function endTest(Test $test, $time) {
+    $this->deprecationEndTest($test, $time);
+    $this->componentEndTest($test, $time);
+    $this->standardsEndTest($test, $time);
   }
+
 }
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
index 84eaaced06df..9b633d483322 100644
--- a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
@@ -5,6 +5,7 @@
 use PHPUnit\Framework\AssertionFailedError;
 use PHPUnit\Framework\TestCase;
 use PHPUnit\Framework\TestSuite;
+use PHPUnit\Util\ErrorHandler;
 
 /**
  * Listens for PHPUnit tests and fails those with invalid coverage annotations.
@@ -167,8 +168,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) {
     if ($type === E_USER_DEPRECATED) {
       return;
     }
-    $error_handler = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler';
-    return $error_handler::handleError($type, $msg, $file, $line, $context);
+    return ErrorHandler::handleError($type, $msg, $file, $line, $context);
   }
 
   /**
@@ -182,7 +182,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) {
    *
    * @group legacy
    *
-   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   * @param \PHPUnit\Framework\Test $test
    *   The test object that has ended its test run.
    * @param float $time
    *   The time the test took.
@@ -190,7 +190,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) {
    * @see http://symfony.com/doc/current/components/phpunit_bridge.html#mark-tests-as-legacy
    */
   private function doEndTest($test, $time) {
-    // \PHPUnit_Framework_Test does not have any useful methods of its own for
+    // \PHPUnit\Framework\Test does not have any useful methods of its own for
     // our purpose, so we have to distinguish between the different known
     // subclasses.
     if ($test instanceof TestCase) {
@@ -212,16 +212,13 @@ private function doEndTest($test, $time) {
   /**
    * Determine if a test object is a test suite regardless of PHPUnit version.
    *
-   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   * @param \PHPUnit\Framework\Test $test
    *   The test object to test if it is a test suite.
    *
    * @return bool
    *   TRUE if it is a test suite, FALSE if not.
    */
   private function isTestSuite($test) {
-    if (class_exists('\PHPUnit_Framework_TestSuite') && $test instanceof \PHPUnit_Framework_TestSuite) {
-      return TRUE;
-    }
     if (class_exists('PHPUnit\Framework\TestSuite') && $test instanceof TestSuite) {
       return TRUE;
     }
@@ -231,7 +228,7 @@ private function isTestSuite($test) {
   /**
    * Reacts to the end of a test.
    *
-   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   * @param \PHPUnit\Framework\Test $test
    *   The test object that has ended its test run.
    * @param float $time
    *   The time the test took.
diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
index 49618b8172b6..b29b11d19df3 100644
--- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
+++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php
@@ -5,39 +5,30 @@
 use PHPUnit\Framework\TestResult;
 use PHPUnit\TextUI\ResultPrinter;
 
-if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
-  class_alias('Drupal\Tests\Listeners\Legacy\HtmlOutputPrinter', 'Drupal\Tests\Listeners\HtmlOutputPrinter');
-  // Using an early return instead of a else does not work when using the
-  // PHPUnit phar due to some weird PHP behavior (the class gets defined without
-  // executing the code before it and so the definition is not properly
-  // conditional).
-}
-else {
+/**
+ * Defines a class for providing html output results for functional tests.
+ *
+ * @internal
+ */
+class HtmlOutputPrinter extends ResultPrinter {
+  use HtmlOutputPrinterTrait;
+
   /**
-   * Defines a class for providing html output results for functional tests.
-   *
-   * @internal
+   * {@inheritdoc}
    */
-  class HtmlOutputPrinter extends ResultPrinter {
-    use HtmlOutputPrinterTrait;
-
-    /**
-     * {@inheritdoc}
-     */
-    public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) {
-      parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
-
-      $this->setUpHtmlOutput();
-    }
+  public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) {
+    parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
 
-    /**
-     * {@inheritdoc}
-     */
-    public function printResult(TestResult $result) {
-      parent::printResult($result);
+    $this->setUpHtmlOutput();
+  }
 
-      $this->printHtmlOutput();
-    }
+  /**
+   * {@inheritdoc}
+   */
+  public function printResult(TestResult $result) {
+    parent::printResult($result);
 
+    $this->printHtmlOutput();
   }
+
 }
diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php b/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php
deleted file mode 100644
index fec2d78264d6..000000000000
--- a/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-namespace Drupal\Tests\Listeners\Legacy;
-
-/**
- * Listens to PHPUnit test runs.
- *
- * @internal
- */
-class AfterSymfonyListener extends \PHPUnit_Framework_BaseTestListener {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function endTest(\PHPUnit_Framework_Test $test, $time) {
-    restore_error_handler();
-  }
-
-}
diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php
deleted file mode 100644
index 1fc603a6f4f1..000000000000
--- a/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-namespace Drupal\Tests\Listeners\Legacy;
-
-use Drupal\Tests\Listeners\DeprecationListenerTrait;
-use Drupal\Tests\Listeners\DrupalComponentTestListenerTrait;
-use Drupal\Tests\Listeners\DrupalStandardsListenerTrait;
-
-/**
- * Listens to PHPUnit test runs.
- *
- * @internal
- *   This class is not public Drupal API.
- */
-class DrupalListener extends \PHPUnit_Framework_BaseTestListener {
-  use DeprecationListenerTrait;
-  use DrupalComponentTestListenerTrait;
-  use DrupalStandardsListenerTrait;
-
-  /**
-   * {@inheritdoc}
-   */
-  public function startTest(\PHPUnit_Framework_Test $test) {
-    $this->deprecationStartTest($test);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function endTest(\PHPUnit_Framework_Test $test, $time) {
-    $this->deprecationEndTest($test, $time);
-    $this->componentEndTest($test, $time);
-    $this->standardsEndTest($test, $time);
-  }
-
-}
diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php
deleted file mode 100644
index 7a332bc2de0b..000000000000
--- a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-namespace Drupal\Tests\Listeners\Legacy;
-
-use Drupal\Tests\Listeners\HtmlOutputPrinterTrait;
-
-/**
- * Defines a class for providing html output results for functional tests.
- *
- * @internal
- */
-class HtmlOutputPrinter extends \PHPUnit_TextUI_ResultPrinter {
-  use HtmlOutputPrinterTrait;
-
-  /**
-   * {@inheritdoc}
-   */
-  public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80) {
-    parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns);
-
-    $this->setUpHtmlOutput();
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function printResult(\PHPUnit_Framework_TestResult $result) {
-    parent::printResult($result);
-
-    $this->printHtmlOutput();
-  }
-
-}
diff --git a/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php b/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php
new file mode 100644
index 000000000000..639e6fa35f3e
--- /dev/null
+++ b/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Drupal\Tests;
+
+/**
+ * Tests existence of the PHPUnit4 backward compatibility classes.
+ *
+ * @group Tests
+ */
+class Phpunit4CompatibilityTest extends UnitTestCase {
+
+  /**
+   * Tests existence of \PHPUnit_Framework_AssertionFailedError.
+   */
+  public function testFrameworkAssertionFailedError() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_AssertionFailedError'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_Constraint_Count.
+   */
+  public function testFrameworkConstraintCount() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_Constraint_Count'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_Error.
+   */
+  public function testFrameworkError() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_Error'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_Error_Warning.
+   */
+  public function FrameworkErrorWarning() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_Error_Warning'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_Exception.
+   */
+  public function testFrameworkException() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_Exception'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_ExpectationFailedException.
+   */
+  public function testFrameworkExpectationFailedException() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_ExpectationFailedException'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder.
+   */
+  public function testFrameworkMockObjectMatcherInvokedRecorder() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_SkippedTestError.
+   */
+  public function testFrameworkSkippedTestError() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_SkippedTestError'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Framework_TestCase.
+   */
+  public function testFrameworkTestCase() {
+    $this->assertTrue(class_exists('\PHPUnit_Framework_TestCase'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Util_Test.
+   */
+  public function testUtilTest() {
+    $this->assertTrue(class_exists('\PHPUnit_Util_Test'));
+  }
+
+  /**
+   * Tests existence of \PHPUnit_Util_XML.
+   */
+  public function testUtilXml() {
+    $this->assertTrue(class_exists('\PHPUnit_Util_XML'));
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
index f7972e1d39b7..4ff7ef00847a 100644
--- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
+++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php
@@ -38,7 +38,6 @@ trait PhpunitCompatibilityTrait {
    * @param object $proxyTarget
    *   Sets the proxy target.
    *
-   * @see \PHPUnit_Framework_TestCase::getMock
    * @see https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0
    *
    * @return \PHPUnit_Framework_MockObject_MockObject
diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php
index 84937ad69c8d..2c320dfaaf61 100644
--- a/core/tests/Drupal/Tests/TestRequirementsTrait.php
+++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php
@@ -3,12 +3,13 @@
 namespace Drupal\Tests;
 
 use Drupal\Core\Extension\ExtensionDiscovery;
+use PHPUnit\Framework\SkippedTestError;
 
 /**
  * Allows test classes to require Drupal modules as dependencies.
  *
- * This trait is assumed to be on a subclass of \PHPUnit_Framework_TestCase, and
- * overrides \PHPUnit_Framework_TestCase::checkRequirements(). This allows the
+ * This trait is assumed to be on a subclass of \PHPUnit\Framework\TestCase, and
+ * overrides \PHPUnit\Framework\TestCase::checkRequirements(). This allows the
  * test to be marked as skipped before any kernel boot processes have happened.
  */
 trait TestRequirementsTrait {
@@ -26,9 +27,9 @@ protected static function getDrupalRoot() {
    * Check module requirements for the Drupal use case.
    *
    * This method is assumed to override
-   * \PHPUnit_Framework_TestCase::checkRequirements().
+   * \PHPUnit\Framework\TestCase::checkRequirements().
    *
-   * @throws \PHPUnit_Framework_SkippedTestError
+   * @throws \PHPUnit\Framework\SkippedTestError
    *   Thrown when the requirements are not met, and this test should be
    *   skipped. Callers should not catch this exception.
    */
@@ -59,7 +60,7 @@ protected function checkRequirements() {
    * @param string[] $annotations
    *   A list of requires annotations from either a method or class annotation.
    *
-   * @throws \PHPUnit_Framework_SkippedTestError
+   * @throws \PHPUnit\Framework\SkippedTestError
    *   Thrown when the requirements are not met, and this test should be
    *   skipped. Callers should not catch this exception.
    */
@@ -83,7 +84,7 @@ private function checkModuleRequirements($root, array $annotations) {
       $list = array_keys($discovery->scan('module'));
       $not_available = array_diff($required_modules, $list);
       if (!empty($not_available)) {
-        throw new \PHPUnit_Framework_SkippedTestError('Required modules: ' . implode(', ', $not_available));
+        throw new SkippedTestError('Required modules: ' . implode(', ', $not_available));
       }
     }
   }
diff --git a/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php
index 4e47f77fe598..91452522093c 100644
--- a/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php
+++ b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php
@@ -4,7 +4,9 @@
 
 use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener as LegacySymfonyTestsListener;
 use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
+use PHPUnit\Framework\AssertionFailedError;
 use PHPUnit\Framework\TestCase;
+use PHPUnit\Util\Test;
 
 /**
  * Adds the ability to dynamically set expected deprecation messages in tests.
@@ -34,19 +36,11 @@ protected function expectDeprecation($message) {
    *   The expected deprecation messages.
    */
   public function expectedDeprecations(array $messages) {
-    if (class_exists('PHPUnit_Util_Test', FALSE)) {
-      $test_util = 'PHPUnit_Util_Test';
-      $assertion_failed_error = 'PHPUnit_Framework_AssertionFailedError';
-    }
-    else {
-      $test_util = 'PHPUnit\Util\Test';
-      $assertion_failed_error = 'PHPUnit\Framework\AssertionFailedError';
-    }
-    if ($this instanceof \PHPUnit_Framework_TestCase || $this instanceof TestCase) {
+    if ($this instanceof TestCase) {
       // Ensure the class or method is in the legacy group.
-      $groups = $test_util::getGroups(get_class($this), $this->getName(FALSE));
+      $groups = Test::getGroups(get_class($this), $this->getName(FALSE));
       if (!in_array('legacy', $groups, TRUE)) {
-        throw new $assertion_failed_error('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.');
+        throw new AssertionFailedError('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.');
       }
 
       // If setting an expected deprecation there is no need to be strict about
@@ -89,7 +83,7 @@ public function expectedDeprecations(array $messages) {
       return;
     }
 
-    throw new $assertion_failed_error('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.');
+    throw new AssertionFailedError('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.');
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index bd183c796174..b8e75799898d 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -104,7 +104,7 @@ protected function assertArrayEquals(array $expected, array $actual, $message =
    *   configuration object names and whose values are key => value arrays for
    *   the configuration object in question. Defaults to an empty array.
    *
-   * @return \PHPUnit_Framework_MockObject_MockBuilder
+   * @return \PHPUnit\Framework\MockObject\MockBuilder
    *   A MockBuilder object for the ConfigFactory with the desired return
    *   values.
    */
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index 7a707472730b..3ea857115efb 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -8,7 +8,17 @@
  */
 
 use Drupal\Component\Assertion\Handle;
-use PHPUnit\Runner\Version;
+use PHPUnit\Framework\AssertionFailedError;
+use PHPUnit\Framework\Constraint\Count;
+use PHPUnit\Framework\Error\Error;
+use PHPUnit\Framework\Error\Warning;
+use PHPUnit\Framework\ExpectationFailedException;
+use PHPUnit\Framework\Exception;
+use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
+use PHPUnit\Framework\SkippedTestError;
+use PHPUnit\Framework\TestCase;
+use PHPUnit\Util\Test;
+use PHPUnit\Util\Xml;
 
 /**
  * Finds all valid extension directories recursively within a given directory.
@@ -151,14 +161,6 @@ function drupal_phpunit_populate_class_loader() {
 // Do class loader population.
 drupal_phpunit_populate_class_loader();
 
-// Ensure we have the correct PHPUnit version for the version of PHP.
-if (class_exists('\PHPUnit_Runner_Version')) {
-  $phpunit_version = \PHPUnit_Runner_Version::id();
-}
-else {
-  $phpunit_version = Version::id();
-}
-
 // Set sane locale settings, to ensure consistent string, dates, times and
 // numbers handling.
 // @see \Drupal\Core\DrupalKernel::bootEnvironment()
@@ -183,16 +185,15 @@ function drupal_phpunit_populate_class_loader() {
 
 // PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on
 // PHPUnit 6 with a minimum of fuss.
-if (version_compare($phpunit_version, '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');
-}
+// @todo provided for BC; remove in Drupal 9.
+class_alias(AssertionFailedError::class, '\PHPUnit_Framework_AssertionFailedError');
+class_alias(Count::class, '\PHPUnit_Framework_Constraint_Count');
+class_alias(Error::class, '\PHPUnit_Framework_Error');
+class_alias(Warning::class, '\PHPUnit_Framework_Error_Warning');
+class_alias(ExpectationFailedException::class, '\PHPUnit_Framework_ExpectationFailedException');
+class_alias(Exception::class, '\PHPUnit_Framework_Exception');
+class_alias(InvokedRecorder::class, '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder');
+class_alias(SkippedTestError::class, '\PHPUnit_Framework_SkippedTestError');
+class_alias(TestCase::class, '\PHPUnit_Framework_TestCase');
+class_alias(Test::class, '\PHPUnit_Util_Test');
+class_alias(Xml::class, '\PHPUnit_Util_XML');
-- 
GitLab