Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Listeners / DrupalComponentTestListenerTrait.php
diff --git a/web/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php b/web/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php
new file mode 100644 (file)
index 0000000..70fa236
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace Drupal\Tests\Listeners;
+
+use Drupal\KernelTests\KernelTestBase;;
+use Drupal\Tests\BrowserTestBase;;
+use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\AssertionFailedError;
+
+/**
+ * Ensures that no component tests are extending a core test base class.
+ *
+ * @internal
+ */
+trait DrupalComponentTestListenerTrait {
+
+  /**
+   * Reacts to the end of a test.
+   *
+   * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
+   *   The test object that has ended its test run.
+   * @param float $time
+   *   The time the test took.
+   */
+  protected function componentEndTest($test, $time) {
+    /** @var \PHPUnit\Framework\Test $test */
+    if (substr($test->toString(), 0, 22) == 'Drupal\Tests\Component') {
+      if ($test instanceof BrowserTestBase || $test instanceof KernelTestBase || $test instanceof UnitTestCase) {
+        $error = new AssertionFailedError('Component tests should not extend a core test base class.');
+        $test->getTestResultObject()->addFailure($test, $error, $time);
+      }
+    }
+  }
+
+}