diff --git a/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php b/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php
index 800bbaba47bce76c36f8d4f9880a03d3765d1848..972b00c39e07a8bb41202a832d6f3deee886b96e 100644
--- a/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php
+++ b/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Entity\EntityConstraintViolationList;
 use Drupal\node\Entity\Node;
+use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait;
 use Drupal\Tests\UnitTestCase;
 use Drupal\user\Entity\User;
 use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
@@ -19,7 +20,7 @@ class EntityResourceValidationTraitTest extends UnitTestCase {
    * @covers ::validate
    */
   public function testValidate() {
-    $trait = $this->getMockForTrait('Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait');
+    $trait = new EntityResourceValidationTraitTestClass();
 
     $method = new \ReflectionMethod($trait, 'validate');
     $method->setAccessible(TRUE);
@@ -59,7 +60,7 @@ public function testFailedValidate() {
 
     $entity->validate()->willReturn($violations);
 
-    $trait = $this->getMockForTrait('Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait');
+    $trait = new EntityResourceValidationTraitTestClass();
 
     $method = new \ReflectionMethod($trait, 'validate');
     $method->setAccessible(TRUE);
@@ -70,3 +71,15 @@ public function testFailedValidate() {
   }
 
 }
+
+/**
+ * A test class to use to test EntityResourceValidationTrait.
+ *
+ * Using ->getMockForTrait is problematic, as this trait is marked internal.
+ * Because the mock doesn't use the \Drupal namespace, the Symfony 4+ class
+ * loader will throw a deprecation error.
+ */
+class EntityResourceValidationTraitTestClass {
+  use EntityResourceValidationTrait;
+
+}