From 13e93c0476742b2c7379a3642bae9865aa8b0346 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Sun, 30 Jul 2017 16:34:33 +1000
Subject: [PATCH] Issue #2866894 by maxocub: Component tests should not use
 Drupal\Tests\UnitTestCase but PHPUnit\Framework\TestCase

---
 core/phpunit.xml.dist                         |  2 ++
 .../AnnotationBridgeDecoratorTest.php         |  4 +--
 .../ZfExtensionManagerSfContainerTest.php     |  4 +--
 .../Component/ClassFinder/ClassFinderTest.php |  8 +++---
 .../Component/Datetime/DateTimePlusTest.php   |  4 +--
 .../Tests/Component/Datetime/TimeTest.php     |  4 +--
 .../Discovery/YamlDirectoryDiscoveryTest.php  | 13 +++++++--
 .../Component/Discovery/YamlDiscoveryTest.php | 13 +++++++--
 .../Tests/Component/DrupalComponentTest.php   |  4 +--
 .../FileCache/FileCacheFactoryTest.php        | 10 ++++---
 .../Component/FileCache/FileCacheTest.php     |  4 +--
 .../FileSystem/RegexDirectoryIteratorTest.php |  4 +--
 .../Tests/Component/Gettext/PoHeaderTest.php  |  4 +--
 .../Tests/Component/Graph/GraphTest.php       |  4 +--
 .../SecuredRedirectResponseTest.php           |  4 +--
 .../PhpStorage/FileStorageReadOnlyTest.php    | 11 ++++++--
 .../Component/PhpStorage/FileStorageTest.php  |  5 +++-
 .../MTimeProtectedFileStorageBase.php         |  6 ++++-
 .../PhpStorage/PhpStorageTestBase.php         | 10 ++++---
 .../Component/Plugin/Context/ContextTest.php  |  4 +--
 .../Component/Plugin/DefaultFactoryTest.php   |  4 +--
 .../Discovery/DiscoveryCachedTraitTest.php    |  4 +--
 .../Plugin/Discovery/DiscoveryTraitTest.php   |  4 +--
 .../StaticDiscoveryDecoratorTest.php          |  8 +++---
 .../Plugin/Factory/ReflectionFactoryTest.php  |  4 +--
 .../Tests/Component/Plugin/PluginBaseTest.php |  4 +--
 .../Plugin/PluginManagerBaseTest.php          | 10 +++----
 .../ProxyBuilder/ProxyBuilderTest.php         |  4 +--
 .../Render/FormattableMarkupTest.php          |  4 +--
 .../Component/Render/HtmlEscapedTextTest.php  |  4 +--
 .../Component/Render/PlainTextOutputTest.php  |  4 +--
 .../Component/Serialization/JsonTest.php      |  4 +--
 .../Component/Serialization/YamlTest.php      |  4 +--
 .../PhpTransliterationTest.php                |  4 +--
 .../Utility/ArgumentsResolverTest.php         |  4 +--
 .../Tests/Component/Utility/BytesTest.php     |  4 +--
 .../Tests/Component/Utility/ColorTest.php     |  4 +--
 .../Utility/CryptRandomFallbackTest.php       |  4 +--
 .../Tests/Component/Utility/CryptTest.php     |  4 +--
 .../Component/Utility/EnvironmentTest.php     |  4 +--
 .../Tests/Component/Utility/HtmlTest.php      | 12 ++++++---
 .../Tests/Component/Utility/ImageTest.php     |  4 +--
 .../Component/Utility/NestedArrayTest.php     |  4 +--
 .../Tests/Component/Utility/NumberTest.php    |  4 +--
 .../Tests/Component/Utility/RandomTest.php    |  4 +--
 .../Tests/Component/Utility/RectangleTest.php |  4 +--
 .../Component/Utility/SafeMarkupTest.php      |  4 +--
 .../Tests/Component/Utility/SortArrayTest.php |  4 +--
 .../Tests/Component/Utility/TimerTest.php     |  4 +--
 .../Tests/Component/Utility/UnicodeTest.php   |  4 +--
 .../Tests/Component/Utility/UrlHelperTest.php |  4 +--
 .../Tests/Component/Utility/UserAgentTest.php | 10 ++++---
 .../Tests/Component/Utility/VariableTest.php  |  4 +--
 .../Tests/Component/Utility/XssTest.php       |  4 +--
 .../Drupal/Tests/Component/Uuid/UuidTest.php  |  4 +--
 .../Listeners/DrupalComponentTestListener.php | 27 +++++++++++++++++++
 56 files changed, 195 insertions(+), 118 deletions(-)
 create mode 100644 core/tests/Drupal/Tests/Listeners/DrupalComponentTestListener.php

diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index c85258d77f49..e5bab48f43d0 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -49,6 +49,8 @@
     </listener>
     <listener class="\Drupal\Tests\Listeners\DrupalStandardsListener">
     </listener>
+    <listener class="\Drupal\Tests\Listeners\DrupalComponentTestListener">
+    </listener>
   </listeners>
   <!-- Filter for coverage reports. -->
   <filter>
diff --git a/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php
index c1e231eb0cc5..62d3c84005c7 100644
--- a/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php
@@ -6,13 +6,13 @@
 use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
 use Drupal\Component\Plugin\Definition\PluginDefinition;
 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
  * @group Plugin
  */
-class AnnotationBridgeDecoratorTest extends UnitTestCase {
+class AnnotationBridgeDecoratorTest extends TestCase {
 
   /**
    * @covers ::getDefinitions
diff --git a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php
index c14bdfb3e595..3aaf9d11297b 100644
--- a/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php
+++ b/core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\Component\Bridge;
 
 use Drupal\Component\Bridge\ZfExtensionManagerSfContainer;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 
 /**
  * @coversDefaultClass \Drupal\Component\Bridge\ZfExtensionManagerSfContainer
  * @group Bridge
  */
-class ZfExtensionManagerSfContainerTest extends UnitTestCase {
+class ZfExtensionManagerSfContainerTest extends TestCase {
 
   /**
    * @covers ::setContainer
diff --git a/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php b/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
index cf1a84b112e3..9e66b6b76c0f 100644
--- a/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
+++ b/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
@@ -4,13 +4,13 @@
 
 use Composer\Autoload\ClassLoader;
 use Drupal\Component\ClassFinder\ClassFinder;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\ClassFinder\ClassFinder
  * @group ClassFinder
  */
-class ClassFinderTest extends UnitTestCase {
+class ClassFinderTest extends TestCase {
 
   /**
    * @covers ::findFile
@@ -20,7 +20,7 @@ public function testFindFile() {
 
     // The full path is returned therefore only tests with
     // assertStringEndsWith() so the test is portable.
-    $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
+    $this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
     $class = 'Not\\A\\Class';
     $this->assertNull($finder->findFile($class));
 
@@ -30,7 +30,7 @@ public function testFindFile() {
     $loader->register();
     $this->assertEquals(__FILE__, $finder->findFile($class));
     // This shouldn't prevent us from finding the original file.
-    $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
+    $this->assertStringEndsWith('core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
 
     // Clean up the additional autoloader after the test.
     $loader->unregister();
diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
index e50e4c43edd9..2becc97a4697 100644
--- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
+++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
@@ -2,14 +2,14 @@
 
 namespace Drupal\Tests\Component\Datetime;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Datetime\DateTimePlus;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Datetime\DateTimePlus
  * @group Datetime
  */
-class DateTimePlusTest extends UnitTestCase {
+class DateTimePlusTest extends TestCase {
 
   /**
    * Test creating dates from string and array input.
diff --git a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php
index 0553451de8c4..4a5fa80205c2 100644
--- a/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php
+++ b/core/tests/Drupal/Tests/Component/Datetime/TimeTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Datetime;
 
 use Drupal\Component\Datetime\Time;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
@@ -15,7 +15,7 @@
  * @runTestsInSeparateProcesses
  * @preserveGlobalState disabled
  */
-class TimeTest extends UnitTestCase {
+class TimeTest extends TestCase {
 
   /**
    * The mocked request stack.
diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
index c9862b642bdb..86134a7bdf10 100644
--- a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
+++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
@@ -4,8 +4,9 @@
 
 use Drupal\Component\Discovery\DiscoveryException;
 use Drupal\Component\Discovery\YamlDirectoryDiscovery;
-use Drupal\Tests\UnitTestCase;
+use Drupal\Component\FileCache\FileCacheFactory;
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\TestCase;
 
 /**
  * YamlDirectoryDiscoveryTest component unit tests.
@@ -14,7 +15,15 @@
  *
  * @group Discovery
  */
-class YamlDirectoryDiscoveryTest extends UnitTestCase {
+class YamlDirectoryDiscoveryTest extends TestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    // Ensure that FileCacheFactory has a prefix.
+    FileCacheFactory::setPrefix('prefix');
+  }
 
   /**
    * Tests YAML directory discovery.
diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
index 897a7889840a..2922586f0faf 100644
--- a/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
+++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDiscoveryTest.php
@@ -2,18 +2,27 @@
 
 namespace Drupal\Tests\Component\Discovery;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Discovery\YamlDiscovery;
+use Drupal\Component\FileCache\FileCacheFactory;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamWrapper;
 use org\bovigo\vfs\vfsStreamDirectory;
+use PHPUnit\Framework\TestCase;
 
 /**
  * YamlDiscovery component unit tests.
  *
  * @group Discovery
  */
-class YamlDiscoveryTest extends UnitTestCase {
+class YamlDiscoveryTest extends TestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    // Ensure that FileCacheFactory has a prefix.
+    FileCacheFactory::setPrefix('prefix');
+  }
 
   /**
    * Tests the YAML file discovery.
diff --git a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
index 7e746d7379a6..fffd26eef072 100644
--- a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
+++ b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php
@@ -2,15 +2,15 @@
 
 namespace Drupal\Tests\Component;
 
-use Drupal\Tests\UnitTestCase;
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\TestCase;
 
 /**
  * General tests for \Drupal\Component that can't go anywhere else.
  *
  * @group Component
  */
-class DrupalComponentTest extends UnitTestCase {
+class DrupalComponentTest extends TestCase {
 
   /**
    * Tests that classes in Component do not use any Core class.
diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
index 1ed036ee8d23..4fe9d3ca09d5 100644
--- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
+++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
@@ -5,13 +5,14 @@
 use Drupal\Component\FileCache\FileCache;
 use Drupal\Component\FileCache\NullFileCache;
 use Drupal\Component\FileCache\FileCacheFactory;
-use Drupal\Tests\UnitTestCase;
+use Drupal\Component\Utility\Random;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\FileCache\FileCacheFactory
  * @group FileCache
  */
-class FileCacheFactoryTest extends UnitTestCase {
+class FileCacheFactoryTest extends TestCase {
 
   /**
    * {@inheritdoc}
@@ -170,7 +171,10 @@ public function testGetSetConfiguration() {
    * @covers ::setPrefix
    */
   public function testGetSetPrefix() {
-    $prefix = $this->randomMachineName();
+    // Random generator.
+    $random = new Random();
+
+    $prefix = $random->name(8, TRUE);
     FileCacheFactory::setPrefix($prefix);
     $this->assertEquals($prefix, FileCacheFactory::getPrefix());
   }
diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
index 9ad30b76b074..15ef1ac9de88 100644
--- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
+++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\FileCache;
 
 use Drupal\Component\FileCache\FileCache;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\FileCache\FileCache
  * @group FileCache
  */
-class FileCacheTest extends UnitTestCase {
+class FileCacheTest extends TestCase {
 
   /**
    * FileCache object used for the tests.
diff --git a/core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php b/core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php
index 6a9cd0caca3d..e8d52bb5b594 100644
--- a/core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php
+++ b/core/tests/Drupal/Tests/Component/FileSystem/RegexDirectoryIteratorTest.php
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\Component\FileSystem;
 
 use Drupal\Component\FileSystem\RegexDirectoryIterator;
-use Drupal\Tests\UnitTestCase;
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\FileSystem\RegexDirectoryIterator
  * @group FileSystem
  */
-class RegexDirectoryIteratorTest extends UnitTestCase {
+class RegexDirectoryIteratorTest extends TestCase {
 
   /**
    * @covers ::accept
diff --git a/core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php b/core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php
index 113f6cdea826..144cc5118b3a 100644
--- a/core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php
+++ b/core/tests/Drupal/Tests/Component/Gettext/PoHeaderTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Gettext;
 
 use Drupal\Component\Gettext\PoHeader;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Unit tests for the Gettext PO file header handling features.
@@ -12,7 +12,7 @@
  *
  * @group Gettext
  */
-class PoHeaderTest extends UnitTestCase {
+class PoHeaderTest extends TestCase {
 
   /**
    * Tests that plural expressions are evaluated correctly.
diff --git a/core/tests/Drupal/Tests/Component/Graph/GraphTest.php b/core/tests/Drupal/Tests/Component/Graph/GraphTest.php
index 9c4a7a528896..940217c64f6f 100644
--- a/core/tests/Drupal/Tests/Component/Graph/GraphTest.php
+++ b/core/tests/Drupal/Tests/Component/Graph/GraphTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Graph;
 
 use Drupal\Component\Graph\Graph;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Graph\Graph
  * @group Graph
  */
-class GraphTest extends UnitTestCase {
+class GraphTest extends TestCase {
 
   /**
    * Test depth-first-search features.
diff --git a/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php b/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php
index f569c0ac6619..17149723af30 100644
--- a/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php
+++ b/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php
@@ -8,7 +8,7 @@
 namespace Drupal\Tests\Component\HttpFoundation;
 
 use Drupal\Component\HttpFoundation\SecuredRedirectResponse;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 use Symfony\Component\HttpFoundation\Cookie;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 
@@ -18,7 +18,7 @@
  * @group Routing
  * @coversDefaultClass \Drupal\Component\HttpFoundation\SecuredRedirectResponse
  */
-class SecuredRedirectResponseTest extends UnitTestCase {
+class SecuredRedirectResponseTest extends TestCase {
 
   /**
    * Test copying of redirect response.
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
index 8b8c95acd9e3..46ef59001ac0 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Component\PhpStorage\FileStorage;
 use Drupal\Component\PhpStorage\FileReadOnlyStorage;
+use Drupal\Component\Utility\Random;
 
 /**
  * @coversDefaultClass \Drupal\Component\PhpStorage\FileReadOnlyStorage
@@ -48,8 +49,11 @@ protected function setUp() {
    * Tests writing with one class and reading with another.
    */
   public function testReadOnly() {
+    // Random generator.
+    $random = new Random();
+
     $php = new FileStorage($this->standardSettings);
-    $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
+    $name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
 
     // Find a global that doesn't exist.
     do {
@@ -85,8 +89,11 @@ public function testWriteable() {
    * @covers ::deleteAll
    */
   public function testDeleteAll() {
+    // Random generator.
+    $random = new Random();
+
     $php = new FileStorage($this->standardSettings);
-    $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
+    $name = $random->name(8, TRUE) . '/' . $random->name(8, TRUE) . '.php';
 
     // Find a global that doesn't exist.
     do {
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
index a1a11ec38dba..14260630782c 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Component\PhpStorage;
 
 use Drupal\Component\PhpStorage\FileStorage;
+use Drupal\Component\Utility\Random;
 
 /**
  * @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage
@@ -55,11 +56,13 @@ public function testWriteable() {
    * @covers ::deleteAll
    */
   public function testDeleteAll() {
+    // Random generator.
+    $random_generator = new Random();
 
     // Write out some files.
     $php = new FileStorage($this->standardSettings);
 
-    $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
+    $name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
 
     // Find a global that doesn't exist.
     do {
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php b/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php
index c36453c3280a..e78751008824 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageBase.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Component\PhpStorage;
 
 use Drupal\Component\Utility\Crypt;
+use Drupal\Component\Utility\Random;
 
 /**
  * Base test class for MTime protected storage.
@@ -36,7 +37,10 @@ abstract class MTimeProtectedFileStorageBase extends PhpStorageTestBase {
   protected function setUp() {
     parent::setUp();
 
-    $this->secret = $this->randomMachineName();
+    // Random generator.
+    $random = new Random();
+
+    $this->secret = $random->name(8, TRUE);
 
     $this->settings = [
       'directory' => $this->directory,
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php b/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php
index f32155e39c85..cc0e79d0e027 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/PhpStorageTestBase.php
@@ -3,13 +3,14 @@
 namespace Drupal\Tests\Component\PhpStorage;
 
 use Drupal\Component\PhpStorage\PhpStorageInterface;
-use Drupal\Tests\UnitTestCase;
+use Drupal\Component\Utility\Random;
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Base test for PHP storages.
  */
-abstract class PhpStorageTestBase extends UnitTestCase {
+abstract class PhpStorageTestBase extends TestCase {
 
   /**
    * A unique per test class directory path to test php storage.
@@ -31,7 +32,10 @@ protected function setUp() {
    * Assert that a PHP storage's load/save/delete operations work.
    */
   public function assertCRUD($php) {
-    $name = $this->randomMachineName() . '/' . $this->randomMachineName() . '.php';
+    // Random generator.
+    $random_generator = new Random();
+
+    $name = $random_generator->name(8, TRUE) . '/' . $random_generator->name(8, TRUE) . '.php';
 
     // Find a global that doesn't exist.
     do {
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
index f320c5544899..6a2cf4667321 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Plugin\Context;
 
 use Drupal\Component\Plugin\Context\Context;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Plugin\Context\Context
  * @group Plugin
  */
-class ContextTest extends UnitTestCase {
+class ContextTest extends TestCase {
 
   /**
    * Data provider for testGetContextValue.
diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
index 28a48f6c1324..b6bb32c84154 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
@@ -8,13 +8,13 @@
 use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry;
 use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface;
 use Drupal\plugin_test\Plugin\plugin_test\fruit\Kale;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Plugin\Factory\DefaultFactory
  * @group Plugin
  */
-class DefaultFactoryTest extends UnitTestCase {
+class DefaultFactoryTest extends TestCase {
 
   /**
    * Tests getPluginClass() with a valid array plugin definition.
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php
index 0f112fb2ef4e..1aa2a365701e 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php
@@ -2,14 +2,14 @@
 
 namespace Drupal\Tests\Component\Plugin\Discovery;
 
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait
  * @uses \Drupal\Component\Plugin\Discovery\DiscoveryTrait
  * @group Plugin
  */
-class DiscoveryCachedTraitTest extends UnitTestCase {
+class DiscoveryCachedTraitTest extends TestCase {
 
   /**
    * Data provider for testGetDefinition().
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
index b0f58c929ae0..c37a4b5a18d3 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Plugin\Discovery;
 
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @group Plugin
  * @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryTrait
  */
-class DiscoveryTraitTest extends UnitTestCase {
+class DiscoveryTraitTest extends TestCase {
 
   /**
    * Data provider for testDoGetDefinition().
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
index 1828d73f36c9..a44721bd9b4e 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
@@ -2,13 +2,13 @@
 
 namespace Drupal\Tests\Component\Plugin\Discovery;
 
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @group Plugin
  * @coversDefaultClass \Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator
  */
-class StaticDiscoveryDecoratorTest extends UnitTestCase {
+class StaticDiscoveryDecoratorTest extends TestCase {
 
   /**
    * Helper method to provide a mocked callback object with expectations.
@@ -171,7 +171,7 @@ public function testGetDefinitions($has_register_definitions, $definitions) {
 
     // Exercise getDefinitions(). It calls parent::getDefinitions() but in this
     // case there will be no side-effects.
-    $this->assertArrayEquals(
+    $this->assertEquals(
       $definitions,
       $mock_decorator->getDefinitions()
     );
@@ -220,7 +220,7 @@ function () {
     $ref_decorated->setValue($mock_decorator, $mock_decorated);
 
     // Exercise __call.
-    $this->assertArrayEquals(
+    $this->assertEquals(
       $args,
       \call_user_func_array([$mock_decorated, $method], $args)
     );
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php
index c6a0adf8596d..3d1a41d11257 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Factory/ReflectionFactoryTest.php
@@ -10,13 +10,13 @@
 namespace Drupal\Tests\Component\Plugin\Factory;
 
 use Drupal\Component\Plugin\Factory\ReflectionFactory;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @group Plugin
  * @coversDefaultClass \Drupal\Component\Plugin\Factory\ReflectionFactory
  */
-class ReflectionFactoryTest extends UnitTestCase {
+class ReflectionFactoryTest extends TestCase {
 
   /**
    * Data provider for testGetInstanceArguments.
diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php
index 0ef8451aba27..de684885ffa6 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/PluginBaseTest.php
@@ -2,13 +2,13 @@
 
 namespace Drupal\Tests\Component\Plugin;
 
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Plugin\PluginBase
  * @group Plugin
  */
-class PluginBaseTest extends UnitTestCase {
+class PluginBaseTest extends TestCase {
 
   /**
    * @dataProvider providerTestGetPluginId
diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
index 24a7b089e71c..a4dd6a76bd9f 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Plugin;
 
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Plugin\PluginManagerBase
  * @group Plugin
  */
-class PluginManagerBaseTest extends UnitTestCase {
+class PluginManagerBaseTest extends TestCase {
 
   /**
    * A callback method for mocking FactoryInterface objects.
@@ -58,7 +58,7 @@ public function testCreateInstance() {
     $configuration_array = ['config' => 'something'];
     $result = $manager->createInstance('valid', $configuration_array);
     $this->assertEquals('valid', $result['plugin_id']);
-    $this->assertArrayEquals($configuration_array, $result['configuration']);
+    $this->assertEquals($configuration_array, $result['configuration']);
   }
 
   /**
@@ -81,13 +81,13 @@ public function testCreateInstanceFallback() {
     $factory_ref->setValue($manager, $this->getMockFactoryInterface(1));
     $no_fallback_result = $manager->createInstance('valid', $configuration_array);
     $this->assertEquals('valid', $no_fallback_result['plugin_id']);
-    $this->assertArrayEquals($configuration_array, $no_fallback_result['configuration']);
+    $this->assertEquals($configuration_array, $no_fallback_result['configuration']);
 
     // Test with fallback interface and invalid plugin_id.
     $factory_ref->setValue($manager, $this->getMockFactoryInterface(2));
     $fallback_result = $manager->createInstance('invalid', $configuration_array);
     $this->assertEquals('invalid_fallback', $fallback_result['plugin_id']);
-    $this->assertArrayEquals($configuration_array, $fallback_result['configuration']);
+    $this->assertEquals($configuration_array, $fallback_result['configuration']);
   }
 
 }
diff --git a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php
index 30bf31050078..1b06ddef3418 100644
--- a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php
+++ b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php
@@ -8,13 +8,13 @@
 namespace Drupal\Tests\Component\ProxyBuilder;
 
 use Drupal\Component\ProxyBuilder\ProxyBuilder;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\ProxyBuilder\ProxyBuilder
  * @group proxy_builder
  */
-class ProxyBuilderTest extends UnitTestCase {
+class ProxyBuilderTest extends TestCase {
 
   /**
    * The tested proxy builder.
diff --git a/core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php b/core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php
index 5d4cad944c15..27445b151b2e 100644
--- a/core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php
+++ b/core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Render;
 
 use Drupal\Component\Render\FormattableMarkup;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests the TranslatableMarkup class.
@@ -11,7 +11,7 @@
  * @coversDefaultClass \Drupal\Component\Render\FormattableMarkup
  * @group utility
  */
-class FormattableMarkupTest extends UnitTestCase {
+class FormattableMarkupTest extends TestCase {
 
   /**
    * The error message of the last error in the error handler.
diff --git a/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php b/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php
index c064e2c2a078..5fc3902f0fac 100644
--- a/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php
+++ b/core/tests/Drupal/Tests/Component/Render/HtmlEscapedTextTest.php
@@ -4,7 +4,7 @@
 
 use Drupal\Component\Render\HtmlEscapedText;
 use Drupal\Component\Render\MarkupInterface;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests the HtmlEscapedText class.
@@ -12,7 +12,7 @@
  * @coversDefaultClass \Drupal\Component\Render\HtmlEscapedText
  * @group utility
  */
-class HtmlEscapedTextTest extends UnitTestCase {
+class HtmlEscapedTextTest extends TestCase {
 
   /**
    * @covers ::__toString
diff --git a/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php b/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php
index 244736a61ccc..8e1101eb7bc6 100644
--- a/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php
+++ b/core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php
@@ -5,13 +5,13 @@
 use Drupal\Component\Render\PlainTextOutput;
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Component\Render\MarkupInterface;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Render\PlainTextOutput
  * @group Utility
  */
-class PlainTextOutputTest extends UnitTestCase {
+class PlainTextOutputTest extends TestCase {
 
   /**
    * Tests ::renderFromHtml().
diff --git a/core/tests/Drupal/Tests/Component/Serialization/JsonTest.php b/core/tests/Drupal/Tests/Component/Serialization/JsonTest.php
index 65552cf5121d..a3a32ad36428 100644
--- a/core/tests/Drupal/Tests/Component/Serialization/JsonTest.php
+++ b/core/tests/Drupal/Tests/Component/Serialization/JsonTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Serialization;
 
 use Drupal\Component\Serialization\Json;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Serialization\Json
  * @group Serialization
  */
-class JsonTest extends UnitTestCase {
+class JsonTest extends TestCase {
 
   /**
    * A test string with the full ASCII table.
diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php
index cee0a94b12db..659862a0440f 100644
--- a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php
+++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php
@@ -7,13 +7,13 @@
 use Drupal\Component\Serialization\Yaml;
 use Drupal\Component\Serialization\YamlPecl;
 use Drupal\Component\Serialization\YamlSymfony;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Serialization\Yaml
  * @group Serialization
  */
-class YamlTest extends UnitTestCase {
+class YamlTest extends TestCase {
 
   /**
    * @var \PHPUnit_Framework_MockObject_MockObject
diff --git a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
index 243fcfd20cdd..2800c51b2001 100644
--- a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
+++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
@@ -4,8 +4,8 @@
 
 use Drupal\Component\Transliteration\PhpTransliteration;
 use Drupal\Component\Utility\Random;
-use Drupal\Tests\UnitTestCase;
 use org\bovigo\vfs\vfsStream;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests Transliteration component functionality.
@@ -14,7 +14,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Transliteration\PhpTransliteration
  */
-class PhpTransliterationTest extends UnitTestCase {
+class PhpTransliterationTest extends TestCase {
 
   /**
    * Tests the PhpTransliteration::removeDiacritics() function.
diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
index 171060906d8b..0dae6ed9c26d 100644
--- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
@@ -8,13 +8,13 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\ArgumentsResolver;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Utility\ArgumentsResolver
  * @group Access
  */
-class ArgumentsResolverTest extends UnitTestCase {
+class ArgumentsResolverTest extends TestCase {
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php
index 35872ac4bbe6..358b5cff99ab 100644
--- a/core/tests/Drupal/Tests/Component/Utility/BytesTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/BytesTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Bytes;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests bytes size parsing helper methods.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Bytes
  */
-class BytesTest extends UnitTestCase {
+class BytesTest extends TestCase {
 
   /**
    * Tests \Drupal\Component\Utility\Bytes::toInt().
diff --git a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php
index e2f1629198fc..cbb9d7e8eb91 100644
--- a/core/tests/Drupal/Tests/Component/Utility/ColorTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/ColorTest.php
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Color;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests Color utility class conversions.
  *
  * @group Utility
  */
-class ColorTest extends UnitTestCase {
+class ColorTest extends TestCase {
 
   /**
    * Tests Color::hexToRgb().
diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptRandomFallbackTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptRandomFallbackTest.php
index de00da6a4b6f..52d91de33f9a 100644
--- a/core/tests/Drupal/Tests/Component/Utility/CryptRandomFallbackTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/CryptRandomFallbackTest.php
@@ -2,8 +2,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\Crypt;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests random byte generation fallback exception situations.
@@ -14,7 +14,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Crypt
  */
-class CryptRandomFallbackTest extends UnitTestCase {
+class CryptRandomFallbackTest extends TestCase {
 
   static protected $functionCalled = 0;
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
index 38743dfd5d34..c87628f75cda 100644
--- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
@@ -2,8 +2,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\Crypt;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests random byte generation.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Crypt
  */
-class CryptTest extends UnitTestCase {
+class CryptTest extends TestCase {
 
   /**
    * Tests random byte generation.
diff --git a/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php b/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php
index 708eee9ab1df..d16795832644 100644
--- a/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Environment;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Test PHP Environment helper methods.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Environment
  */
-class EnvironmentTest extends UnitTestCase {
+class EnvironmentTest extends TestCase {
 
   /**
    * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
index 46283421373f..3638408a02a5 100644
--- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
@@ -5,7 +5,8 @@
 use Drupal\Component\Render\MarkupInterface;
 use Drupal\Component\Render\MarkupTrait;
 use Drupal\Component\Utility\Html;
-use Drupal\Tests\UnitTestCase;
+use Drupal\Component\Utility\Random;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests \Drupal\Component\Utility\Html.
@@ -14,7 +15,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Html
  */
-class HtmlTest extends UnitTestCase {
+class HtmlTest extends TestCase {
 
   /**
    * {@inheritdoc}
@@ -354,11 +355,14 @@ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_hos
   public function providerTestTransformRootRelativeUrlsToAbsolute() {
     $data = [];
 
+    // Random generator.
+    $random = new Random();
+
     // One random tag name.
-    $tag_name = strtolower($this->randomMachineName());
+    $tag_name = strtolower($random->name(8, TRUE));
 
     // A site installed either in the root of a domain or a subdirectory.
-    $base_paths = ['/', '/subdir/' . $this->randomMachineName() . '/'];
+    $base_paths = ['/', '/subdir/' . $random->name(8, TRUE) . '/'];
 
     foreach ($base_paths as $base_path) {
       // The only attribute that has more than just a URL as its value, is
diff --git a/core/tests/Drupal/Tests/Component/Utility/ImageTest.php b/core/tests/Drupal/Tests/Component/Utility/ImageTest.php
index eec1375eaef7..be3cdd75eb02 100644
--- a/core/tests/Drupal/Tests/Component/Utility/ImageTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/ImageTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Image;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Utility\Image
  * @group Image
  */
-class ImageTest extends UnitTestCase {
+class ImageTest extends TestCase {
 
   /**
    * Tests all control flow branches in image_dimensions_scale().
diff --git a/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
index 0371ebb3503d..9601e81f513c 100644
--- a/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/NestedArrayTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\NestedArray;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Utility\NestedArray
  * @group Utility
  */
-class NestedArrayTest extends UnitTestCase {
+class NestedArrayTest extends TestCase {
 
   /**
    * Form array to check.
diff --git a/core/tests/Drupal/Tests/Component/Utility/NumberTest.php b/core/tests/Drupal/Tests/Component/Utility/NumberTest.php
index 8d415de92b39..1fc05d3ad78e 100644
--- a/core/tests/Drupal/Tests/Component/Utility/NumberTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/NumberTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Number;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests number manipulation utilities.
@@ -14,7 +14,7 @@
  *
  * @see \Drupal\Component\Utility\Number
  */
-class NumberTest extends UnitTestCase {
+class NumberTest extends TestCase {
 
   /**
    * Tests Number::validStep() without offset.
diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
index b122c3affda8..64f0eaac1bd4 100644
--- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Random;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests random data generation.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Random
  */
-class RandomTest extends UnitTestCase {
+class RandomTest extends TestCase {
 
   /**
    * The first random string passed to the test callback.
diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
index 1f7394a05b12..af6f9a515c38 100644
--- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
@@ -3,13 +3,13 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Rectangle;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @coversDefaultClass \Drupal\Component\Utility\Rectangle
  * @group Image
  */
-class RectangleTest extends UnitTestCase {
+class RectangleTest extends TestCase {
 
   /**
    * Tests wrong rectangle width.
diff --git a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
index 0a7fc77d811b..7f249d9bea14 100644
--- a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php
@@ -12,7 +12,7 @@
 use Drupal\Component\Render\MarkupInterface;
 use Drupal\Component\Render\MarkupTrait;
 use Drupal\Component\Utility\UrlHelper;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests marking strings as safe.
@@ -20,7 +20,7 @@
  * @group Utility
  * @coversDefaultClass \Drupal\Component\Utility\SafeMarkup
  */
-class SafeMarkupTest extends UnitTestCase {
+class SafeMarkupTest extends TestCase {
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
index 890d17171ebc..7503cc27100c 100644
--- a/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/SortArrayTest.php
@@ -2,8 +2,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\SortArray;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests the SortArray component.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\SortArray
  */
-class SortArrayTest extends UnitTestCase {
+class SortArrayTest extends TestCase {
 
   /**
    * Tests SortArray::sortByWeightElement() input against expected output.
diff --git a/core/tests/Drupal/Tests/Component/Utility/TimerTest.php b/core/tests/Drupal/Tests/Component/Utility/TimerTest.php
index 4aeebc588e4d..a7cbf8732eb4 100644
--- a/core/tests/Drupal/Tests/Component/Utility/TimerTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/TimerTest.php
@@ -2,8 +2,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\Timer;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests the Timer system.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Timer
  */
-class TimerTest extends UnitTestCase {
+class TimerTest extends TestCase {
 
   /**
    * Tests Timer::read() time accumulation accuracy across multiple restarts.
diff --git a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
index b834d2bbed38..6bfc6cb0d2f7 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php
@@ -2,8 +2,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\Unicode;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Test unicode handling features implemented in Unicode component.
@@ -12,7 +12,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Unicode
  */
-class UnicodeTest extends UnitTestCase {
+class UnicodeTest extends TestCase {
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
index 17e0dd3db086..faff21bb322e 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\UrlHelper;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * @group Utility
  *
  * @coversDefaultClass \Drupal\Component\Utility\UrlHelper
  */
-class UrlHelperTest extends UnitTestCase {
+class UrlHelperTest extends TestCase {
 
   /**
    * Provides test data for testBuildQuery().
diff --git a/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php b/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php
index d804e1aab376..f18d071df1d5 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UserAgentTest.php
@@ -2,8 +2,9 @@
 
 namespace Drupal\Tests\Component\Utility;
 
+use Drupal\Component\Utility\Random;
 use Drupal\Component\Utility\UserAgent;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests bytes size parsing helper methods.
@@ -12,7 +13,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\UserAgent
  */
-class UserAgentTest extends UnitTestCase {
+class UserAgentTest extends TestCase {
 
   /**
    * Helper method to supply language codes to testGetBestMatchingLangcode().
@@ -82,6 +83,9 @@ public function testGetBestMatchingLangcode($accept_language, $expected) {
    *   - Expected best matching language code.
    */
   public function providerTestGetBestMatchingLangcode() {
+    // Random generator.
+    $random = new Random();
+
     return [
       // Equal qvalue for each language, choose the site preferred one.
       ['en,en-US,fr-CA,fr,es-MX', 'en'],
@@ -141,7 +145,7 @@ public function providerTestGetBestMatchingLangcode() {
       ['', FALSE],
       ['de,pl', FALSE],
       ['iecRswK4eh', FALSE],
-      [$this->randomMachineName(10), FALSE],
+      [$random->name(10, TRUE), FALSE],
 
       // Chinese langcodes.
       ['zh-cn, en-us;q=0.90, en;q=0.80, zh;q=0.70', 'zh-hans'],
diff --git a/core/tests/Drupal/Tests/Component/Utility/VariableTest.php b/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
index 9096f87bfe98..3fda715c29f2 100644
--- a/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
@@ -7,8 +7,8 @@
 
 namespace Drupal\Tests\Component\Utility;
 
-use Drupal\Tests\UnitTestCase;
 use Drupal\Component\Utility\Variable;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Test variable export functionality in Variable component.
@@ -18,7 +18,7 @@
  *
  * @coversDefaultClass \Drupal\Component\Utility\Variable
  */
-class VariableTest extends UnitTestCase {
+class VariableTest extends TestCase {
 
   /**
    * Data provider for testExport().
diff --git a/core/tests/Drupal/Tests/Component/Utility/XssTest.php b/core/tests/Drupal/Tests/Component/Utility/XssTest.php
index e7832a31f0f0..0664f94272cc 100644
--- a/core/tests/Drupal/Tests/Component/Utility/XssTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/XssTest.php
@@ -5,7 +5,7 @@
 use Drupal\Component\Utility\Html;
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Component\Utility\Xss;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * XSS Filtering tests.
@@ -20,7 +20,7 @@
  * - CVE-2002-1806, ~CVE-2005-0682, ~CVE-2005-2106, CVE-2005-3973,
  *   CVE-2006-1226 (= rev. 1.112?), CVE-2008-0273, CVE-2008-3740.
  */
-class XssTest extends UnitTestCase {
+class XssTest extends TestCase {
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php b/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php
index a93dd0981a78..e40da71387b7 100644
--- a/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php
+++ b/core/tests/Drupal/Tests/Component/Uuid/UuidTest.php
@@ -7,14 +7,14 @@
 use Drupal\Component\Uuid\Com;
 use Drupal\Component\Uuid\Pecl;
 use Drupal\Component\Uuid\Php;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests the handling of Universally Unique Identifiers (UUIDs).
  *
  * @group Uuid
  */
-class UuidTest extends UnitTestCase {
+class UuidTest extends TestCase {
 
   /**
    * Tests generating valid UUIDs.
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListener.php b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListener.php
new file mode 100644
index 000000000000..c3496773057b
--- /dev/null
+++ b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListener.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Drupal\Tests\Listeners;
+
+use Drupal\KernelTests\KernelTestBase;;
+use Drupal\Tests\BrowserTestBase;;
+use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\BaseTestListener;
+
+/**
+ * Ensures that no component tests are extending a core test base class.
+ */
+class DrupalComponentTestListener extends BaseTestListener {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function endTest(\PHPUnit_Framework_Test $test, $time) {
+    if (substr($test->toString(), 0, 22) == 'Drupal\Tests\Component') {
+      if ($test instanceof BrowserTestBase || $test instanceof KernelTestBase || $test instanceof UnitTestCase) {
+        $error = new \PHPUnit_Framework_AssertionFailedError('Component tests should not extend a core test base class.');
+        $test->getTestResultObject()->addFailure($test, $error, $time);
+      }
+    }
+  }
+
+}
-- 
GitLab