diff --git a/core/modules/update/tests/src/Unit/UpdateFetcherTest.php b/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
index c3e447d1fc..61c767deda 100644
--- a/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
+++ b/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
@@ -28,7 +28,7 @@ class UpdateFetcherTest extends UnitTestCase {
    */
   protected function setUp() {
     $config_factory = $this->getConfigFactoryStub(['update.settings' => ['fetch_url' => 'http://www.example.com']]);
-    $http_client_mock = $this->getMock('\GuzzleHttp\ClientInterface');
+    $http_client_mock = $this->createMock('\GuzzleHttp\ClientInterface');
     $this->updateFetcher = new UpdateFetcher($config_factory, $http_client_mock);
   }
 
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index 32c97b63b5..91da81edf8 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -20,6 +20,7 @@
 use Drupal\simpletest\AssertContentTrait;
 use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\ConfigTestTrait;
+use Drupal\Tests\Phpunit5FCTrait;
 use Drupal\Tests\RandomGeneratorTrait;
 use Drupal\Tests\TestRequirementsTrait;
 use Drupal\simpletest\TestServiceProvider;
@@ -76,6 +77,7 @@
   use RandomGeneratorTrait;
   use ConfigTestTrait;
   use TestRequirementsTrait;
+  use Phpunit5FCTrait;
 
   /**
    * {@inheritdoc}
diff --git a/core/tests/Drupal/Tests/Phpunit5FCTrait.php b/core/tests/Drupal/Tests/Phpunit5FCTrait.php
new file mode 100644
index 0000000000..17f7b73577
--- /dev/null
+++ b/core/tests/Drupal/Tests/Phpunit5FCTrait.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Drupal\Tests;
+
+/**
+ * This trait makes tests forward compatible with PHPUnit 5 and above.
+ */
+trait Phpunit5FCTrait {
+
+  /**
+   * Returns a mock object for the specified class using the available method.
+   *
+   * The getMock method is deprecated in PHPUnit 5 but the createMock method is
+   * not available in PHPUnit 4. To provide backward compatibility this trait
+   * provides the getMock method and uses createMock if this method is
+   * available on the parent class.
+   *
+   * @param string $originalClassName
+   *   Name of the class to mock.
+   * @param array|null $methods
+   *   When provided, only methods whose names are in the array are replaced
+   *   with a configurable test double. The behavior of the other methods is not
+   *   changed. Providing null means that no methods will be replaced.
+   * @param array $arguments
+   *   Parameters to pass to the original class' constructor.
+   * @param string $mockClassName
+   *   Class name for the generated test double class.
+   * @param bool $callOriginalConstructor
+   *   Can be used to disable the call to the original class' constructor.
+   * @param bool $callOriginalClone
+   *   Can be used to disable the call to the original class' clone constructor.
+   * @param bool $callAutoload
+   *   Can be used to disable __autoload() during the generation of the test
+   *   double class.
+   * @param bool $cloneArguments
+   * @param bool $callOriginalMethods
+   * @param object $proxyTarget
+   *
+   * @see \PHPUnit_Framework_TestCase::getMock
+   * @see https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0
+   *
+   * @return \PHPUnit_Framework_MockObject_MockObject
+   *
+   * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
+   *   Use \Drupal\Tests\Phpunit5FCTrait::createMock() instead.
+   *
+   * @see https://www.drupal.org/node/2907725
+   */
+  public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) {
+    return $this->createMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
+  }
+
+  /**
+   * Returns a mock object for the specified class using the available method.
+   *
+   * The getMock method is deprecated in PHPUnit 5 but the createMock method is
+   * not available in PHPUnit 4. To provide forward compatibility this trait
+   * provides the createMock method and uses createMock if this method is
+   * available on the parent class or falls back to getMock if it isn't.
+   *
+   * @param string $originalClassName
+   *   Name of the class to mock.
+   * @param array|null $methods
+   *   When provided, only methods whose names are in the array are replaced
+   *   with a configurable test double. The behavior of the other methods is not
+   *   changed. Providing null means that no methods will be replaced.
+   * @param array $arguments
+   *   Parameters to pass to the original class' constructor.
+   * @param string $mockClassName
+   *   Class name for the generated test double class.
+   * @param bool $callOriginalConstructor
+   *   Can be used to disable the call to the original class' constructor.
+   * @param bool $callOriginalClone
+   *   Can be used to disable the call to the original class' clone constructor.
+   * @param bool $callAutoload
+   *   Can be used to disable __autoload() during the generation of the test
+   *   double class.
+   * @param bool $cloneArguments
+   * @param bool $callOriginalMethods
+   * @param object $proxyTarget
+   *
+   * @see \PHPUnit_Framework_TestCase::getMock
+   *
+   * @return \PHPUnit_Framework_MockObject_MockObject
+   */
+  public function createMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) {
+    if ($this->isPhpunit5()) {
+      return parent::createMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
+    }
+    return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
+  }
+
+  /**
+   * Checks if the trait is used in a class extending the PHPUnit 5 TestCase.
+   *
+   * @return bool
+   */
+  private function isPhpunit5() {
+    // Get the parent class of the currently running test class.
+    $parent = get_parent_class($this);
+    // Ensure that the method_exists() check on PHPUnit 5's createMock method is
+    // carried out on the first parent of $this that does not have access to
+    // this trait's methods. This is because the trait also has a method called
+    // createMock(). Most often the check will be made on
+    // \PHPUnit\Framework\TestCase.
+    while (method_exists($parent, 'isPhpunit5')) {
+      $parent = get_parent_class($parent);
+    }
+    return method_exists($parent, 'createMock');
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php b/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php
new file mode 100644
index 0000000000..621003f6b3
--- /dev/null
+++ b/core/tests/Drupal/Tests/Phpunit5FCTraitTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Drupal\Tests;
+
+/**
+ * Test the PHPUnit 5 forward compatibility trait.
+ *
+ * @coversDefaultClass \Drupal\Tests\Phpunit5FCTrait
+ * @group simpletest
+ * @group Tests
+ */
+class Phpunit5FCTraitTest extends UnitTestCase {
+
+  /**
+   * Test that getMock is available and calls the correct parent method.
+   *
+   * @covers ::getMock
+   * @dataProvider providerMockVersions
+   */
+  public function testGetMock($className, $expected) {
+    $class = new $className();
+    $this->assertSame($expected, $class->getMock($this->randomMachineName()));
+  }
+
+  /**
+   * Test that createMock is available and calls the correct parent method.
+   *
+   * @covers ::createMock
+   * @dataProvider providerMockVersions
+   */
+  public function testCreateMock($className, $expected) {
+    $class = new $className();
+    $this->assertSame($expected, $class->createMock($this->randomMachineName()));
+  }
+
+  /**
+   * Return the class names and the string they return.
+   *
+   * @return array
+   */
+  public function providerMockVersions() {
+    return [
+      [UnitTestCasePhpunit4TestClass::class, 'PHPUnit 4'],
+      [UnitTestCasePhpunit4TestClassExtends::class, 'PHPUnit 4'],
+      [UnitTestCasePhpunit5TestClass::class, 'PHPUnit 5'],
+      [UnitTestCasePhpunit5TestClassExtends::class, 'PHPUnit 5'],
+    ];
+  }
+
+}
+
+/**
+ * Test class for \PHPUnit\Framework\TestCase in PHPUnit 4.
+ */
+class Phpunit4TestClass {
+  public function getMock($originalClassName) {
+    return 'PHPUnit 4';
+  }
+
+}
+
+/**
+ * Test class for \PHPUnit\Framework\TestCase in PHPUnit 5.
+ */
+class Phpunit5TestClass {
+  public function createMock($originalClassName) {
+    return 'PHPUnit 5';
+  }
+
+}
+
+/**
+ * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
+ */
+class UnitTestCasePhpunit4TestClass extends Phpunit4TestClass {
+  use Phpunit5FCTrait;
+
+}
+
+/**
+ * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 4.
+ */
+class UnitTestCasePhpunit4TestClassExtends extends UnitTestCasePhpunit4TestClass {
+}
+
+/**
+ * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 5.
+ */
+class UnitTestCasePhpunit5TestClass extends Phpunit5TestClass {
+  use Phpunit5FCTrait;
+
+}
+
+/**
+ * Test class for \Drupal\Tests\UnitTestCase with PHPUnit 5.
+ */
+class UnitTestCasePhpunit5TestClassExtends extends UnitTestCasePhpunit5TestClass {
+}
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index 24ad6801bf..b4ac0c3805 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -17,6 +17,8 @@
  */
 abstract class UnitTestCase extends TestCase {
 
+  use Phpunit5FCTrait;
+
   /**
    * The random generator.
    *
@@ -135,7 +137,7 @@ public function getConfigFactoryStub(array $configs = []) {
     }
     // Construct a config factory with the array of configuration object stubs
     // as its return map.
-    $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
+    $config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
     $config_factory->expects($this->any())
       ->method('get')
       ->will($this->returnValueMap($config_get_map));
@@ -157,7 +159,7 @@ public function getConfigFactoryStub(array $configs = []) {
    *   A mocked config storage.
    */
   public function getConfigStorageStub(array $configs) {
-    $config_storage = $this->getMock('Drupal\Core\Config\NullStorage');
+    $config_storage = $this->createMock('Drupal\Core\Config\NullStorage');
     $config_storage->expects($this->any())
       ->method('listAll')
       ->will($this->returnValue(array_keys($configs)));
@@ -211,7 +213,7 @@ protected function getBlockMockWithMachineName($machine_name) {
    *   A mock translation object.
    */
   public function getStringTranslationStub() {
-    $translation = $this->getMock('Drupal\Core\StringTranslation\TranslationInterface');
+    $translation = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');
     $translation->expects($this->any())
       ->method('translate')
       ->willReturnCallback(function ($string, array $args = [], array $options = []) use ($translation) {
@@ -241,7 +243,7 @@ public function getStringTranslationStub() {
    *   The container with the cache tags invalidator service.
    */
   protected function getContainerWithCacheTagsInvalidator(CacheTagsInvalidatorInterface $cache_tags_validator) {
-    $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+    $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
     $container->expects($this->any())
       ->method('get')
       ->with('cache_tags.invalidator')
@@ -258,7 +260,7 @@ protected function getContainerWithCacheTagsInvalidator(CacheTagsInvalidatorInte
    *   The class resolver stub.
    */
   protected function getClassResolverStub() {
-    $class_resolver = $this->getMock('Drupal\Core\DependencyInjection\ClassResolverInterface');
+    $class_resolver = $this->createMock('Drupal\Core\DependencyInjection\ClassResolverInterface');
     $class_resolver->expects($this->any())
       ->method('getInstanceFromDefinition')
       ->will($this->returnCallback(function ($class) {
