diff --git a/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php b/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
index 960730908f18fc0ceeccd11bbd31d5b85b5aebed..e3964762d7d34a5f15fefb321ce20256b8eec933 100644
--- a/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
+++ b/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
@@ -267,7 +267,7 @@ public function testLoadByEntityTypeBundle($config_id, ContentLanguageSettings $
       ->with('language_content_settings')
       ->willReturn($this->configEntityStorageInterface);
 
-    $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
     $entity_type_repository->expects($this->any())
       ->method('getEntityTypeFromClass')
       ->with(ContentLanguageSettings::class)
diff --git a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
index cf2ff03c4aa42f9de3dd93d106ff00218f25b42c..5eaea98aacc644d6a466787b991df7a496168a5c 100644
--- a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
+++ b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
@@ -86,7 +86,7 @@ public function testCalculateDependencies() {
       ->with('image_style')
       ->willReturn($storage);
 
-    $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
     $entity_type_repository->expects($this->any())
       ->method('getEntityTypeFromClass')
       ->with('Drupal\image\Entity\ImageStyle')
diff --git a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
index 7e5bebfbf2e4ec7fef6f98751050c36f1e3b69e5..f46b8932033a166785bf2a7e8deb799538ead682 100644
--- a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
+++ b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
@@ -32,7 +32,7 @@ public function testTitleQuery() {
     ], 'user_role');
 
     // Creates a stub entity storage;
-    $role_storage = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityStorageInterface');
+    $role_storage = $this->createMock('Drupal\Core\Entity\EntityStorageInterface');
     $role_storage->expects($this->any())
       ->method('loadMultiple')
       ->willReturnMap([
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
index e48973a39f65f3f7fddca076c2285618224d5d96..fcf770d322eedbebe15f37b67872ee0c88106725 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
@@ -49,9 +49,7 @@ public function testGetContextValue($expected, $context_value, $is_required, $da
     // throwing an exception if the definition requires it.
     else {
       // Create a mock definition.
-      $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
-        ->onlyMethods(['isRequired', 'getDataType'])
-        ->getMockForAbstractClass();
+      $mock_definition = $this->createMock('Drupal\Component\Plugin\Context\ContextDefinitionInterface');
 
       // Set expectation for isRequired().
       $mock_definition->expects($this->once())
@@ -103,9 +101,7 @@ public function providerHasContextValue() {
    * @dataProvider providerHasContextValue
    */
   public function testHasContextValue($has_context_value, $default_value): void {
-    $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
-      ->onlyMethods(['getDefaultValue'])
-      ->getMockForAbstractClass();
+    $mock_definition = $this->createMock('Drupal\Component\Plugin\Context\ContextDefinitionInterface');
 
     $mock_definition->expects($this->atLeastOnce())
       ->method('getDefaultValue')
@@ -121,9 +117,7 @@ public function testHasContextValue($has_context_value, $default_value): void {
    * @covers ::getContextValue
    */
   public function testDefaultValue() {
-    $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
-      ->onlyMethods(['getDefaultValue'])
-      ->getMockForAbstractClass();
+    $mock_definition = $this->createMock('Drupal\Component\Plugin\Context\ContextDefinitionInterface');
 
     $mock_definition->expects($this->once())
       ->method('getDefaultValue')
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
index 51e5b83202b20707f27a36fd4d4477ff4bf65e93..8ad7a989266b759f507764d99bc66e43aef0a021 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\Tests\Component\Plugin\Discovery;
 
+use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
 use Drupal\Component\Plugin\Discovery\StaticDiscovery;
 use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator;
 use PHPUnit\Framework\TestCase;
@@ -26,9 +27,7 @@ class StaticDiscoveryDecoratorTest extends TestCase {
    *   called once.
    */
   public function getRegisterDefinitionsCallback() {
-    $mock_callable = $this->getMockBuilder(StaticDiscoveryDecoratorTestMockInterface::class)
-      ->onlyMethods(['registerDefinitionsCallback'])
-      ->getMock();
+    $mock_callable = $this->createMock(StaticDiscoveryDecoratorTestMockInterface::class);
     // Set expectations for the callback method.
     $mock_callable->expects($this->once())
       ->method('registerDefinitionsCallback');
@@ -88,9 +87,7 @@ public function testGetDefinition($expected, $has_register_definitions, $excepti
     $ref_definitions->setValue($mock_decorator, []);
 
     // Mock a decorated object.
-    $mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
-      ->onlyMethods(['getDefinitions'])
-      ->getMockForAbstractClass();
+    $mock_decorated = $this->createMock(DiscoveryInterface::class);
     // Return our definitions from getDefinitions().
     $mock_decorated->expects($this->once())
       ->method('getDefinitions')
@@ -155,9 +152,7 @@ public function testGetDefinitions($has_register_definitions, $definitions) {
     $ref_definitions->setValue($mock_decorator, []);
 
     // Mock a decorated object.
-    $mock_decorated = $this->getMockBuilder('Drupal\Component\Plugin\Discovery\DiscoveryInterface')
-      ->onlyMethods(['getDefinitions'])
-      ->getMockForAbstractClass();
+    $mock_decorated = $this->createMock(DiscoveryInterface::class);
     // Our mocked method will return any arguments sent to it.
     $mock_decorated->expects($this->once())
       ->method('getDefinitions')
diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
index b4c5a6952e4d59b10e170a2ec85ac25b377c331d..ad9ba1ac9696fd9c4742625ae01a0d24abaf2e2b 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php
@@ -38,9 +38,7 @@ public function createInstanceCallback() {
    * Generates a mocked FactoryInterface object with known properties.
    */
   public function getMockFactoryInterface($expects_count) {
-    $mock_factory = $this->getMockBuilder('Drupal\Component\Plugin\Factory\FactoryInterface')
-      ->onlyMethods(['createInstance'])
-      ->getMockForAbstractClass();
+    $mock_factory = $this->createMock('Drupal\Component\Plugin\Factory\FactoryInterface');
     $mock_factory->expects($this->exactly($expects_count))
       ->method('createInstance')
       ->willReturnCallback([$this, 'createInstanceCallback']);
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php b/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
index f1ed747139552af1cc8130ea25a1a686d3f2f028..b0f0c23ef958f6452d8ac2cf86d1bbf1c8d44e1b 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
@@ -61,9 +61,7 @@ public function provideGetMessageText() {
    */
   public function testGetMessageText($expected, $config) {
     // Root package has our config.
-    $root = $this->getMockBuilder(RootPackageInterface::class)
-      ->onlyMethods(['getExtra'])
-      ->getMockForAbstractClass();
+    $root = $this->createMock(RootPackageInterface::class);
     $root->expects($this->once())
       ->method('getExtra')
       ->willReturn($config);
@@ -78,9 +76,7 @@ public function testGetMessageText($expected, $config) {
    */
   public function testDefaultFile() {
     // Root package has no extra field.
-    $root = $this->getMockBuilder(RootPackageInterface::class)
-      ->onlyMethods(['getExtra'])
-      ->getMockForAbstractClass();
+    $root = $this->createMock(RootPackageInterface::class);
     $root->expects($this->once())
       ->method('getExtra')
       ->willReturn([]);
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
index bf154ca10fc5c3d808ecff0eb38094a51005ba25..442379723d3ddcb2d5635c454dfa7e34253b5d0c 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
@@ -38,9 +38,7 @@ public function testGetPathsForPackageMixedCase() {
    */
   public function testNoRootMergeConfig() {
     // Root package has no extra field.
-    $root = $this->getMockBuilder(RootPackageInterface::class)
-      ->onlyMethods(['getExtra'])
-      ->getMockForAbstractClass();
+    $root = $this->createMock(RootPackageInterface::class);
     $root->expects($this->once())
       ->method('getExtra')
       ->willReturn([]);
@@ -61,9 +59,7 @@ public function testNoRootMergeConfig() {
    */
   public function testRootMergeConfig() {
     // Root package has configuration in extra.
-    $root = $this->getMockBuilder(RootPackageInterface::class)
-      ->onlyMethods(['getExtra'])
-      ->getMockForAbstractClass();
+    $root = $this->createMock(RootPackageInterface::class);
     $root->expects($this->once())
       ->method('getExtra')
       ->willReturn([
@@ -90,9 +86,7 @@ public function testRootMergeConfig() {
    */
   public function testMixedCaseConfigCleanupPackages() {
     // Root package has configuration in extra.
-    $root = $this->getMockBuilder(RootPackageInterface::class)
-      ->onlyMethods(['getExtra'])
-      ->getMockForAbstractClass();
+    $root = $this->createMock(RootPackageInterface::class);
     $root->expects($this->once())
       ->method('getExtra')
       ->willReturn([
diff --git a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php
index 0a5fcee9c451a9e9b9c16e467310bb47ee6eab95..1339f6ef243d68ed83f9455e058466a91297f117 100644
--- a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php
+++ b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php
@@ -113,8 +113,7 @@ public function testCleanAllPackages() {
       ->method('getAllCleanupPaths')
       ->willReturn(['drupal/package' => ['tests']]);
 
-    $package = $this->getMockBuilder(PackageInterface::class)
-      ->getMockForAbstractClass();
+    $package = $this->createMock(PackageInterface::class);
     $package->expects($this->any())
       ->method('getName')
       ->willReturn('drupal/package');
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index 6d7951bc97436236678b523340abe9c2e9ecb794..2cf483611f2e16a6561c14e314c03afdde8598a0 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -619,9 +619,7 @@ public function testGetFields($expected, $include_computed, $is_computed, $field
     // Mock field definition objects for each element of $field_definitions.
     $mocked_field_definitions = [];
     foreach ($field_definitions as $name) {
-      $mock_definition = $this->getMockBuilder('Drupal\Core\Field\FieldDefinitionInterface')
-        ->onlyMethods(['isComputed'])
-        ->getMockForAbstractClass();
+      $mock_definition = $this->createMock('Drupal\Core\Field\FieldDefinitionInterface');
       // Set expectations for isComputed(). isComputed() gets called whenever
       // $include_computed is FALSE, but not otherwise. It returns the value of
       // $is_computed.
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php
index bc6621b719e1ebf337b79cfd61e3c7bee27d19f9..de87cce4435dd6ff63e74f3fc6b333048f171826 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityStorageBaseTest.php
@@ -22,9 +22,7 @@ class EntityStorageBaseTest extends UnitTestCase {
    *   The mocked entity.
    */
   public function generateEntityInterface($id) {
-    $mock_entity = $this->getMockBuilder('\Drupal\Core\Entity\EntityInterface')
-      ->onlyMethods(['id'])
-      ->getMockForAbstractClass();
+    $mock_entity = $this->createMock('\Drupal\Core\Entity\EntityInterface');
     $mock_entity->expects($this->any())
       ->method('id')
       ->willReturn((string) $id);
@@ -153,9 +151,7 @@ public function testLoadMultiple($expected, $load_multiple, $query) {
       ->willReturn($load_multiple);
 
     // Make our EntityTypeInterface mock so that we can turn off static caching.
-    $mock_entity_type = $this->getMockBuilder('\Drupal\Core\Entity\EntityTypeInterface')
-      ->onlyMethods(['isStaticallyCacheable'])
-      ->getMockForAbstractClass();
+    $mock_entity_type = $this->createMock('\Drupal\Core\Entity\EntityTypeInterface');
     // Disallow caching.
     $mock_entity_type->expects($this->any())
       ->method('isStaticallyCacheable')
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index c564a3e17f1ec6f74e59cdb1bb91df16305a7f1d..2ac0a72f001df2edc7a7173cb0d312edcd6b2212 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -103,7 +103,7 @@ protected function setUp(): void {
       ->method('getListCacheTags')
       ->willReturn([$this->entityTypeId . '_list']);
 
-    $this->entityTypeManager = $this->getMockForAbstractClass(EntityTypeManagerInterface::class);
+    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
     $this->entityTypeManager->expects($this->any())
       ->method('getDefinition')
       ->with($this->entityTypeId)
@@ -255,7 +255,7 @@ public function testLoad() {
 
     $class_name = get_class($this->entity);
 
-    $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
     $entity_type_repository->expects($this->once())
       ->method('getEntityTypeFromClass')
       ->with($class_name)
@@ -289,7 +289,7 @@ public function testLoadMultiple() {
 
     $class_name = get_class($this->entity);
 
-    $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
     $entity_type_repository->expects($this->once())
       ->method('getEntityTypeFromClass')
       ->with($class_name)
@@ -321,7 +321,7 @@ public function testCreate() {
 
     $class_name = get_class($this->entity);
 
-    $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+    $entity_type_repository = $this->createMock(EntityTypeRepositoryInterface::class);
     $entity_type_repository->expects($this->once())
       ->method('getEntityTypeFromClass')
       ->with($class_name)
diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
index 3b4de81d80b11deafd2697d3572a53dcaf501004..89b78dd560e43bde86e7ebbf4ad6ed7ba8170ff5 100644
--- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
@@ -195,7 +195,7 @@ protected function setUp(): void {
       ->method('createFieldItemList')
       ->willReturn($this->fieldItemList);
 
-    $this->entityFieldManager = $this->getMockForAbstractClass(EntityFieldManagerInterface::class);
+    $this->entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
 
     $container = new ContainerBuilder();
     $container->set('entity_type.manager', $this->entityTypeManager);
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
index 6a54511a545a2b5913fd2f61e83aa0279c78dd02..c0b5c289615d13b6a91f53216f90d470d87d8311 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
@@ -35,15 +35,7 @@ public function providerGetDataDefinition() {
    */
   public function testGetDataDefinition($is_multiple) {
     $data_type = 'valid';
-    $mock_data_definition = $this->getMockBuilder(ContextDefinitionInterface::class)
-      ->onlyMethods([
-        'getConstraints',
-        'setLabel',
-        'setDescription',
-        'setRequired',
-        'setConstraints',
-      ])
-      ->getMockForAbstractClass();
+    $mock_data_definition = $this->createMock(ContextDefinitionInterface::class);
     $mock_data_definition->expects($this->once())
       ->method('setLabel')
       ->willReturnSelf();
@@ -118,8 +110,7 @@ public function testGetDataDefinitionInvalidType($is_multiple) {
     // Since we're trying to make getDataDefinition() throw an exception in
     // isolation, we use a data type which is not valid.
     $data_type = 'not_valid';
-    $mock_data_definition = $this->getMockBuilder('\Drupal\Core\TypedData\ListDataDefinitionInterface')
-      ->getMockForAbstractClass();
+    $mock_data_definition = $this->createMock('\Drupal\Core\TypedData\ListDataDefinitionInterface');
 
     // Follow code paths for both multiple and non-multiple definitions.
     $create_definition_method = 'createDataDefinition';
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php
index 4e2d49a288298dc5a22a3e68e3aa30bc22ea4b88..ba24da9008c29f1d403754c5af0b087ca0cdad91 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php
@@ -85,9 +85,7 @@ public function testNullDataValue() {
    */
   public function testSetContextValueTypedData() {
 
-    $this->contextDefinition = $this->getMockBuilder('Drupal\Core\Plugin\Context\ContextDefinitionInterface')
-      ->onlyMethods(['getDefaultValue', 'getDataDefinition'])
-      ->getMockForAbstractClass();
+    $this->contextDefinition = $this->createMock('Drupal\Core\Plugin\Context\ContextDefinitionInterface');
 
     $typed_data = $this->createMock('Drupal\Core\TypedData\TypedDataInterface');
     $context = new Context($this->contextDefinition, $typed_data);
@@ -141,9 +139,7 @@ public function testSetContextValueCacheableDependency() {
   protected function setUpDefaultValue($default_value = NULL) {
     $mock_data_definition = $this->createMock('Drupal\Core\TypedData\DataDefinitionInterface');
 
-    $this->contextDefinition = $this->getMockBuilder('Drupal\Core\Plugin\Context\ContextDefinitionInterface')
-      ->onlyMethods(['getDefaultValue', 'getDataDefinition'])
-      ->getMockForAbstractClass();
+    $this->contextDefinition = $this->createMock('Drupal\Core\Plugin\Context\ContextDefinitionInterface');
 
     $this->contextDefinition->expects($this->once())
       ->method('getDefaultValue')