diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php
index 57108d3fcefa4eba80eb9ac11e15efc02bece425..1b3d34784bed8d19853078c73ba481a4eee99d7d 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 b246e0557d2454e22287c4bc45e14d1d2ce74369..8610bab794de15259917a75a902b20d932789de5 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 19f199b0bba7d515337e4216a98745ce1a122a36..b5697b3c787ae37e2067827bcb5f0a2f92a4ed50 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 569e71c57846c2ad87aac7bb39518ba4c795c9ce..ee530d629ab51fa5c99df8128246f7cb5d97feab 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 453f527579c2387a21772c796de6b5b21cc0a3cf..45a017c4104e5d11f8b03b0682b3ead30fbea00c 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 a8175263b37307448ca9458886317b26b8225548..19650ecbaaac761a5b4bd45440e9c7e49e53b3cd 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 e14f0cf7a303e1be235f6d927de87e4bd60b9c58..b9db4dcb73ee6379f42479e22bebde4954568888 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 f98a08908465513f5dc8f07574f8dea7f4a642cd..9368954cd2ecff3a45c53dd04a6ff48fdebf4016 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 a4990cc36c3f9eca5b3f08e2f72739760181ff88..b0f81565b2f83c7d0b9e2ec3eef566d8b43e740f 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 10a76c1caddf901cc9291f026ff204567d2a9e6a..186a7325a7e722510cbdcad8be02b4751cb4133a 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 f66dd6e46d562d2ca192f85698ba51b256ec4f84..01d17fc4bab6dedacb838f3c5ad253d24a4f0a83 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 dcb0e2b313522957393f7b6b0b5cb8ebcd28dce9..a3d57f5c8c059251756ef2aa76f5a7c920732474 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 757d5fbfbc149c91f17e7e1fd9bccbb82fb30d0f..978ab70e3a3695394d875ddd79b06e5dd5b1eca1 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 ede995aa5f95efb3a538fab7da4f78f680f27735..90896144b2169075824c12b15337c7093f59b649 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 2bd2e03755c55e021abaeaf5c3c9e729fdec51f7..d3e148c4cd3a15087711e0be7b54af1dc449b978 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 90b0f1c6ce904ee8d8ac20af7c6b380f1d119ffc..4fd49f09cbe9a1ff3ad70e4f6e3f205c80e5414f 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 3c11f43a381ad8ac1672d9b6f3fd281c60ccb252..7ef81b9f2a15ea7506f4ee3479636ef1ba90a42b 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() {}
+
+}