From 7c6f4aec37eaf2c1f8c789666fda50485e0206aa Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 3 May 2018 22:46:49 +0100
Subject: [PATCH] Issue #2428753 by borisson_, daffie, dawehner, franksj: Do
 not allow PHPUnit tests to test an interface

---
 .../Core/Entity/EntityRevisionTranslationTest.php      |  2 +-
 .../Tests/Listeners/DrupalStandardsListenerTrait.php   | 10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php
index addbad2e0f40..34969ebd4d16 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionTranslationTest.php
@@ -161,7 +161,7 @@ public function testDefaultRevision() {
   }
 
   /**
-   * @covers \Drupal\Core\Entity\RevisionableInterface::setNewRevision
+   * @covers \Drupal\Core\Entity\ContentEntityBase::setNewRevision
    */
   public function testSetNewRevision() {
     $user = $this->createUser();
diff --git a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
index 3352d900b380..84eaaced06df 100644
--- a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
@@ -42,7 +42,7 @@ private function fail(TestCase $test, $message) {
    *   TRUE if the class exists, FALSE otherwise.
    */
   private function classExists($class) {
-    return class_exists($class, TRUE) || trait_exists($class, TRUE) || interface_exists($class, TRUE);
+    return class_exists($class, TRUE) || trait_exists($class, TRUE);
   }
 
   /**
@@ -71,7 +71,10 @@ private function checkValidCoversForTest(TestCase $test) {
       $default_class = reset($annotations['class']['coversDefaultClass']);
       // Check whether the default class exists.
       $valid_default_class = $this->classExists($default_class);
-      if (!$valid_default_class) {
+      if (!$valid_default_class && interface_exists($default_class)) {
+        $this->fail($test, "@coversDefaultClass refers to an interface '$default_class' and those can not be tested.");
+      }
+      elseif (!$valid_default_class) {
         $this->fail($test, "@coversDefaultClass does not exist '$default_class'");
       }
     }
@@ -105,6 +108,9 @@ private function checkValidCoversForTest(TestCase $test) {
               $this->fail($test, "@covers invalid syntax: Needs '::' or class does not exist in $covers");
               return;
             }
+            elseif (interface_exists($class)) {
+              $this->fail($test, "@covers refers to an interface '$class' and those can not be tested.");
+            }
             else {
               $this->fail($test, '@covers class does not exist ' . $class);
               return;
-- 
GitLab