From 77286bebfcdf9876f40b1e49494ac536fd6e7c62 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 4 Oct 2019 12:59:14 +0100
Subject: [PATCH] Issue #3085673 by mikelutz: [Symfony 4]
 EntityResourceValidationTraitTest should not get a mock for an internal trait

---
 .../Unit/EntityResourceValidationTraitTest.php  | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php b/core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php
index 800bbaba47bc..972b00c39e07 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;
+
+}
-- 
GitLab