From 88ca0c51a2d0819ac63ea320ae95736b4e98ab33 Mon Sep 17 00:00:00 2001
From: catch <catch56@gmail.com>
Date: Fri, 28 Oct 2022 13:41:59 +0100
Subject: [PATCH] Issue #3309745 by andypost, Berdir, longwave, Wim Leers,
 Taran2L, mondrake, alexpott: Fix dynamic property deprecations and other unit
 test failures for PHP 8.2

---
 .../tests/src/Unit/MailHandlerTest.php        |  3 ++-
 .../tests/src/Kernel/EntityDisplayTest.php    | 14 ++++------
 .../src/Kernel/EntityFormDisplayTest.php      | 14 ++++------
 .../src/Unit/NodeOperationAccessTest.php      |  6 -----
 .../Unit/Normalizer/EntityNormalizerTest.php  |  7 ++---
 .../src/TypedData/ComputedString.php          |  7 +++++
 .../src/Functional/Database/FakeRecord.php    | 18 +++++++++++++
 .../KernelTests/Core/Database/FetchTest.php   |  2 +-
 .../DependencyInjection/ContainerTest.php     |  9 +++++--
 .../ContainerAwareEventDispatcherTest.php     |  1 +
 .../Tests/Component/Utility/VariableTest.php  |  5 +++-
 .../Entity/ConfigEntityBaseUnitTest.php       |  7 +++--
 .../Tests/Core/Entity/EntityLinkTest.php      |  3 ++-
 .../Tests/Core/Entity/EntityUnitTest.php      | 11 +++++++-
 .../Tests/Core/Entity/EntityUrlTest.php       | 24 +++++++++++------
 .../KeyValueEntityStorageTest.php             | 26 +++++++++++++------
 .../Core/Form/ConfigFormBaseTraitTest.php     | 12 +++++++--
 17 files changed, 115 insertions(+), 54 deletions(-)

diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php
index 57108d3fcefa..1b3d34784bed 100644
--- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php
+++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Tests\UnitTestCase;
+use Drupal\user\Entity\User;
 
 /**
  * @coversDefaultClass \Drupal\contact\MailHandler
@@ -292,7 +293,7 @@ public function getSendMailMessages() {
    *   Mock sender for testing.
    */
   protected function getMockSender($anonymous = TRUE, $mail_address = 'anonymous@drupal.org') {
-    $sender = $this->createMock('\Drupal\Core\Session\AccountInterface');
+    $sender = $this->createMock(User::class);
     $sender->expects($this->once())
       ->method('isAnonymous')
       ->willReturn($anonymous);
diff --git a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
index b246e0557d24..8610bab794de 100644
--- a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
+++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
@@ -262,20 +262,16 @@ public function testFieldComponent() {
     $this->assertEquals($default_formatter, $formatter->getPluginId());
     $this->assertEquals($formatter_settings, $formatter->getSettings());
 
-    // Check that the formatter is statically persisted, by assigning an
-    // arbitrary property and reading it back.
-    $random_value = $this->randomString();
-    $formatter->randomValue = $random_value;
-    $formatter = $display->getRenderer($field_name);
-    $this->assertEquals($random_value, $formatter->randomValue);
+    // Check that the formatter is statically persisted.
+    $this->assertSame($formatter, $display->getRenderer($field_name));
 
     // Check that changing the definition creates a new formatter.
     $display->setComponent($field_name, [
       'type' => 'field_test_multiple',
     ]);
-    $formatter = $display->getRenderer($field_name);
-    $this->assertEquals('field_test_multiple', $formatter->getPluginId());
-    $this->assertFalse(isset($formatter->randomValue));
+    $renderer = $display->getRenderer($field_name);
+    $this->assertEquals('field_test_multiple', $renderer->getPluginId());
+    $this->assertNotSame($formatter, $renderer);
 
     // Check that the display has dependencies on the field and the module that
     // provides the formatter.
diff --git a/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php
index 19f199b0bba7..b5697b3c787a 100644
--- a/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php
+++ b/core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php
@@ -103,20 +103,16 @@ public function testFieldComponent() {
     $this->assertEquals($default_widget, $widget->getPluginId());
     $this->assertEquals($widget_settings, $widget->getSettings());
 
-    // Check that the widget is statically persisted, by assigning an
-    // arbitrary property and reading it back.
-    $random_value = $this->randomString();
-    $widget->randomValue = $random_value;
-    $widget = $form_display->getRenderer($field_name);
-    $this->assertEquals($random_value, $widget->randomValue);
+    // Check that the widget is statically persisted.
+    $this->assertSame($widget, $form_display->getRenderer($field_name));
 
     // Check that changing the definition creates a new widget.
     $form_display->setComponent($field_name, [
       'type' => 'field_test_multiple',
     ]);
-    $widget = $form_display->getRenderer($field_name);
-    $this->assertEquals('test_field_widget', $widget->getPluginId());
-    $this->assertFalse(isset($widget->randomValue));
+    $renderer = $form_display->getRenderer($field_name);
+    $this->assertEquals('test_field_widget', $renderer->getPluginId());
+    $this->assertNotSame($widget, $renderer);
 
     // Check that specifying an unknown widget (e.g. case of a disabled module)
     // gets stored as is in the display, but results in the default widget being
diff --git a/core/modules/node/tests/src/Unit/NodeOperationAccessTest.php b/core/modules/node/tests/src/Unit/NodeOperationAccessTest.php
index 569e71c57846..ee530d629ab5 100644
--- a/core/modules/node/tests/src/Unit/NodeOperationAccessTest.php
+++ b/core/modules/node/tests/src/Unit/NodeOperationAccessTest.php
@@ -7,7 +7,6 @@
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
-use Drupal\Core\Entity\RevisionableEntityBundleInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Session\AccountInterface;
@@ -118,11 +117,6 @@ public function testRevisionOperations($operation, array $hasPermissionMap, $ass
     $accessControl = new NodeAccessControlHandler($entityType, $grants, $entityTypeManager);
     $accessControl->setModuleHandler($moduleHandler);
 
-    $nodeType = $this->createMock(RevisionableEntityBundleInterface::class);
-    $typeProperty = new \stdClass();
-    $typeProperty->entity = $nodeType;
-    $node->type = $typeProperty;
-
     $access = $accessControl->access($node, $operation, $account, FALSE);
     $this->assertEquals($assertAccess, $access);
   }
diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
index 453f527579c2..45a017c4104e 100644
--- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
+++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\serialization\Unit\Normalizer;
 
+use Drupal\Core\Entity\ContentEntityBase;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\EntityTypeRepositoryInterface;
@@ -187,7 +188,7 @@ public function testDenormalizeWithValidBundle() {
     $key_1 = $this->createMock(FieldItemListInterface::class);
     $key_2 = $this->createMock(FieldItemListInterface::class);
 
-    $entity = $this->createMock(FieldableEntityInterface::class);
+    $entity = $this->createMock(ContentEntityBase::class);
     $entity->expects($this->exactly(2))
       ->method('get')
       ->willReturnMap([
@@ -340,7 +341,7 @@ public function testDenormalizeWithNoBundle() {
     $key_1 = $this->createMock(FieldItemListInterface::class);
     $key_2 = $this->createMock(FieldItemListInterface::class);
 
-    $entity = $this->createMock(FieldableEntityInterface::class);
+    $entity = $this->createMock(ContentEntityBase::class);
     $entity->expects($this->exactly(2))
       ->method('get')
       ->willReturnMap([
@@ -409,7 +410,7 @@ public function testDenormalizeWithNoFieldableEntityType() {
     $storage->expects($this->once())
       ->method('create')
       ->with($test_data)
-      ->willReturn($this->createMock('Drupal\Core\Entity\EntityInterface'));
+      ->willReturn($this->createMock(ContentEntityBase::class));
 
     $this->entityTypeManager->expects($this->once())
       ->method('getStorage')
diff --git a/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php b/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php
index a8175263b373..19650ecbaaac 100644
--- a/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php
+++ b/core/modules/system/tests/modules/entity_test/src/TypedData/ComputedString.php
@@ -11,6 +11,13 @@
  */
 class ComputedString extends TypedData implements CacheableDependencyInterface {
 
+  /**
+   * The data value.
+   *
+   * @var mixed
+   */
+  protected $value;
+
   /**
    * {@inheritdoc}
    */
diff --git a/core/modules/system/tests/src/Functional/Database/FakeRecord.php b/core/modules/system/tests/src/Functional/Database/FakeRecord.php
index e14f0cf7a303..b9db4dcb73ee 100644
--- a/core/modules/system/tests/src/Functional/Database/FakeRecord.php
+++ b/core/modules/system/tests/src/Functional/Database/FakeRecord.php
@@ -18,6 +18,24 @@ class FakeRecord {
    */
   public $fakeArg;
 
+  /**
+   * The property used in tests.
+   *
+   * @see \Drupal\KernelTests\Core\Database\FetchTest
+   *
+   * @var string
+   */
+  public string $name;
+
+  /**
+   * The property used in tests.
+   *
+   * @see \Drupal\KernelTests\Core\Database\DatabaseTestBase
+   *
+   * @var string
+   */
+  public string $job;
+
   /**
    * Constructs a FakeRecord object with an optional constructor argument.
    *
diff --git a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
index f98a08908465..9368954cd2ec 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php
@@ -82,7 +82,7 @@ public function testQueryFetchClass() {
   /**
    * Confirms that we can fetch a record into a class using fetchObject.
    *
-   * @see \Drupal\system\Tests\Database\FakeRecord
+   * @see \Drupal\Tests\system\Functional\Database\FakeRecord
    * @see \Drupal\Core\Database\StatementPrefetch::fetchObject
    */
   public function testQueryFetchObjectClass() {
diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
index a4990cc36c3f..b0f81565b2f8 100644
--- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
@@ -168,7 +168,7 @@ public function testGet() {
     $this->assertEquals($some_parameter, $service->getSomeParameter(), '%some_config% was injected via constructor.');
     $this->assertEquals($this->container, $service->getContainer(), 'Container was injected via setter injection.');
     $this->assertEquals($some_other_parameter, $service->getSomeOtherParameter(), '%some_other_config% was injected via setter injection.');
-    $this->assertEquals('foo', $service->_someProperty, 'Service has added properties.');
+    $this->assertEquals('foo', $service->someProperty, 'Service has added properties.');
   }
 
   /**
@@ -741,7 +741,7 @@ protected function getMockContainerDefinition() {
         $this->getServiceCall('other.service'),
         $this->getParameterCall('some_config'),
       ]),
-      'properties' => $this->getCollection(['_someProperty' => 'foo']),
+      'properties' => $this->getCollection(['someProperty' => 'foo']),
       'calls' => [
         [
           'setContainer',
@@ -1103,6 +1103,11 @@ class MockService {
    */
   protected $someOtherParameter;
 
+  /**
+   * @var string
+   */
+  public string $someProperty;
+
   /**
    * Constructs a MockService object.
    *
diff --git a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
index 10a76c1caddf..186a7325a7e7 100644
--- a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
+++ b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
@@ -559,6 +559,7 @@ public function __invoke() {
 
 class TestEventListener {
 
+  public $name;
   public $preFooInvoked = FALSE;
   public $postFooInvoked = FALSE;
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/VariableTest.php b/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
index f66dd6e46d56..01d17fc4bab6 100644
--- a/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/VariableTest.php
@@ -162,7 +162,10 @@ public function providerTestExport() {
         new \stdClass(),
       ],
       [
-        // A not-stdClass object.
+        // A not-stdClass object. Since PHP 8.2 exported namespace is prefixed,
+        // see https://github.com/php/php-src/pull/8233 for reasons.
+        PHP_VERSION_ID >= 80200 ?
+        "\Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))" :
         "Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))",
         new StubVariableTestClass(),
       ],
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index dcb0e2b31352..a3d57f5c8c05 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Config\Entity;
 
 use Drupal\Component\Plugin\PluginManagerInterface;
+use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Config\Schema\SchemaIncompleteException;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -517,11 +518,11 @@ public function testSort() {
         ],
       ]);
 
-    $entity_a = $this->createMock('\Drupal\Core\Config\Entity\ConfigEntityInterface');
+    $entity_a = $this->createMock(ConfigEntityBase::class);
     $entity_a->expects($this->atLeastOnce())
       ->method('label')
       ->willReturn('foo');
-    $entity_b = $this->createMock('\Drupal\Core\Config\Entity\ConfigEntityInterface');
+    $entity_b = $this->createMock(ConfigEntityBase::class);
     $entity_b->expects($this->atLeastOnce())
       ->method('label')
       ->willReturn('bar');
@@ -648,6 +649,8 @@ class TestConfigEntityWithPluginCollections extends ConfigEntityBaseWithPluginCo
 
   protected $pluginManager;
 
+  protected $the_plugin_collection_config;
+
   public function setPluginManager(PluginManagerInterface $plugin_manager) {
     $this->pluginManager = $plugin_manager;
   }
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
index 757d5fbfbc14..978ab70e3a36 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core\Entity;
 
+use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Language\Language;
@@ -93,7 +94,7 @@ public function testToLink($entity_label, $link_text, $expected_text, $link_rel
       ->willReturn($entity_type);
 
     /** @var \Drupal\Core\Entity\Entity $entity */
-    $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityBase', [
+    $entity = $this->getMockForAbstractClass(ConfigEntityBase::class, [
       ['id' => $entity_id, 'label' => $entity_label, 'langcode' => 'es'],
       $entity_type_id,
     ]);
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index ede995aa5f95..90896144b216 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -5,6 +5,7 @@
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityBase;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\EntityTypeRepositoryInterface;
@@ -121,7 +122,7 @@ protected function setUp(): void {
     $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
     \Drupal::setContainer($container);
 
-    $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityBase', [$this->values, $this->entityTypeId]);
+    $this->entity = new EntityBaseTest($this->values, $this->entityTypeId);
   }
 
   /**
@@ -618,3 +619,11 @@ public function testCacheMaxAge() {
   }
 
 }
+
+class EntityBaseTest extends EntityBase {
+  public $id;
+  public $langcode;
+  public $uuid;
+  public $label;
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
index 2bd2e03755c5..d3e148c4cd3a 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -100,7 +100,7 @@ class EntityUrlTest extends UnitTestCase {
    * @covers ::toUrl
    */
   public function testToUrlNoId() {
-    $entity = $this->getEntity(EntityBase::class, []);
+    $entity = $this->getEntity(UrlTestEntity::class, []);
 
     $this->expectException(EntityMalformedException::class);
     $this->expectExceptionMessage('The "' . $this->entityTypeId . '" entity cannot have a URI as it does not have an ID');
@@ -123,7 +123,7 @@ public function testToUrlNoId() {
    */
   public function testToUrlLinkTemplates($link_template, $expected_route_name) {
     $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
-    $entity = $this->getEntity(EntityBase::class, $values);
+    $entity = $this->getEntity(UrlTestEntity::class, $values);
     $this->registerLinkTemplate($link_template);
 
     /** @var \Drupal\Core\Url $url */
@@ -220,7 +220,7 @@ public function providerTestToUrlLinkTemplateRevision() {
    * @covers ::urlRouteParameters
    */
   public function testToUrlLinkTemplateNoId($link_template, $expected_route_name) {
-    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);
+    $entity = $this->getEntity(UrlTestEntity::class, ['id' => $this->entityId]);
     $this->registerLinkTemplate($link_template);
 
     /** @var \Drupal\Core\Url $url */
@@ -265,7 +265,7 @@ public function providerTestToUrlLinkTemplateNoId() {
    */
   public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters) {
     $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
-    $entity = $this->getEntity(EntityBase::class, $values);
+    $entity = $this->getEntity(UrlTestEntity::class, $values);
     $this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
     $this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
     $this->entityType->getKey('bundle')->willReturn($bundle_key);
@@ -310,7 +310,7 @@ public function providerTestToUrlLinkTemplateAddForm() {
    * @covers ::linkTemplates
    */
   public function testToUrlUriCallbackUndefined(array $bundle_info, $uri_callback) {
-    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);
+    $entity = $this->getEntity(UrlTestEntity::class, ['id' => $this->entityId]);
 
     $this->registerBundleInfo($bundle_info);
     $this->entityType->getUriCallback()->willReturn($uri_callback);
@@ -351,7 +351,7 @@ public function providerTestToUrlUriCallbackUndefined() {
    * @dataProvider providerTestToUrlUriCallback
    */
   public function testToUrlUriCallback(array $bundle_info, $uri_callback) {
-    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId, 'langcode' => $this->langcode]);
+    $entity = $this->getEntity(UrlTestEntity::class, ['id' => $this->entityId, 'langcode' => $this->langcode]);
 
     $this->registerBundleInfo($bundle_info);
     $this->entityType->getUriCallback()->willReturn($uri_callback);
@@ -385,7 +385,7 @@ public function providerTestToUrlUriCallback() {
    * @covers ::uriRelationships
    */
   public function testUriRelationships() {
-    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);
+    $entity = $this->getEntity(UrlTestEntity::class, ['id' => $this->entityId]);
 
     $container_builder = new ContainerBuilder();
     $url_generator = $this->createMock(UrlGeneratorInterface::class);
@@ -505,4 +505,12 @@ protected function registerBundleInfo($bundle_info) {
 
 }
 
-abstract class RevisionableEntity extends EntityBase implements RevisionableInterface {}
+class UrlTestEntity extends EntityBase {
+  public $id;
+  public $langcode;
+  public $uuid;
+  public $label;
+
+}
+
+abstract class RevisionableEntity extends UrlTestEntity implements RevisionableInterface {}
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index 90b0f1c6ce90..4fd49f09cbe9 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -5,6 +5,7 @@
 use Drupal\Core\Cache\MemoryCache\MemoryCache;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityBase;
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityMalformedException;
@@ -197,7 +198,7 @@ public function testCreateWithoutUuidKey() {
    * @return \Drupal\Core\Entity\EntityInterface
    */
   public function testCreate() {
-    $entity = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [], ['toArray']);
+    $entity = $this->getMockEntity(EntityBaseTest::class, [], ['toArray']);
     $this->entityType->expects($this->once())
       ->method('getClass')
       ->willReturn(get_class($entity));
@@ -442,7 +443,7 @@ public function testSaveInvalid() {
   public function testSaveDuplicate() {
     $this->setUpKeyValueEntityStorage();
 
-    $entity = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'foo']]);
+    $entity = $this->getMockEntity(EntityBaseTest::class, [['id' => 'foo']]);
     $entity->enforceIsNew();
     $this->keyValueStore->expects($this->once())
       ->method('has')
@@ -497,8 +498,8 @@ public function testLoadMissingEntity() {
    * @covers ::doLoadMultiple
    */
   public function testLoadMultipleAll() {
-    $expected['foo'] = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'foo']]);
-    $expected['bar'] = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'bar']]);
+    $expected['foo'] = $this->getMockEntity(EntityBaseTest::class, [['id' => 'foo']]);
+    $expected['bar'] = $this->getMockEntity(EntityBaseTest::class, [['id' => 'bar']]);
     $this->entityType->expects($this->once())
       ->method('getClass')
       ->willReturn(get_class(reset($expected)));
@@ -522,7 +523,7 @@ public function testLoadMultipleAll() {
    * @covers ::doLoadMultiple
    */
   public function testLoadMultipleIds() {
-    $entity = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'foo']]);
+    $entity = $this->getMockEntity(EntityBaseTest::class, [['id' => 'foo']]);
     $this->entityType->expects($this->once())
       ->method('getClass')
       ->willReturn(get_class($entity));
@@ -563,8 +564,8 @@ public function testDeleteRevision() {
    * @covers ::doDelete
    */
   public function testDelete() {
-    $entities['foo'] = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'foo']]);
-    $entities['bar'] = $this->getMockEntity('Drupal\Core\Entity\EntityBase', [['id' => 'bar']]);
+    $entities['foo'] = $this->getMockEntity(EntityBaseTest::class, [['id' => 'foo']]);
+    $entities['bar'] = $this->getMockEntity(EntityBaseTest::class, [['id' => 'bar']]);
     $this->setUpKeyValueEntityStorage();
 
     $this->moduleHandler->expects($this->exactly(8))
@@ -611,7 +612,7 @@ public function testDeleteNothing() {
    *
    * @return \Drupal\Core\Entity\EntityInterface|\PHPUnit\Framework\MockObject\MockObject
    */
-  public function getMockEntity($class = 'Drupal\Core\Entity\EntityBase', array $arguments = [], $methods = []) {
+  public function getMockEntity($class = EntityBaseTest::class, array $arguments = [], $methods = []) {
     // Ensure the entity is passed at least an array of values and an entity
     // type ID
     if (!isset($arguments[0])) {
@@ -625,6 +626,15 @@ public function getMockEntity($class = 'Drupal\Core\Entity\EntityBase', array $a
 
 }
 
+class EntityBaseTest extends EntityBase {
+  public $id;
+  public $langcode;
+  public $uuid;
+  public $label;
+  public $original;
+
+}
+
 namespace Drupal\Core\Entity\KeyValueStore;
 
 if (!defined('SAVED_NEW')) {
diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
index 3c11f43a381a..7ef81b9f2a15 100644
--- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core\Form;
 
+use Drupal\Core\Form\ConfigFormBaseTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -15,7 +16,7 @@ class ConfigFormBaseTraitTest extends UnitTestCase {
    */
   public function testConfig() {
 
-    $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait');
+    $trait = $this->createPartialMock(ConfiguredTrait::class, ['getEditableConfigNames']);
     // Set up some configuration in a mocked config factory.
     $trait->configFactory = $this->getConfigFactoryStub([
       'editable.config' => [],
@@ -58,7 +59,6 @@ public function testConfigFactoryException() {
    */
   public function testConfigFactoryExceptionInvalidProperty() {
     $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait');
-    $trait->configFactory = TRUE;
     $config_method = new \ReflectionMethod($trait, 'config');
     $config_method->setAccessible(TRUE);
 
@@ -69,3 +69,11 @@ public function testConfigFactoryExceptionInvalidProperty() {
   }
 
 }
+
+class ConfiguredTrait {
+  use ConfigFormBaseTrait;
+  public $configFactory;
+
+  protected function getEditableConfigNames() {}
+
+}
-- 
GitLab