3 namespace Drupal\Tests\Listeners;
5 use Drupal\KernelTests\KernelTestBase;;
6 use Drupal\Tests\BrowserTestBase;;
7 use Drupal\Tests\UnitTestCase;
8 use PHPUnit\Framework\AssertionFailedError;
11 * Ensures that no component tests are extending a core test base class.
15 trait DrupalComponentTestListenerTrait {
18 * Reacts to the end of a test.
20 * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
21 * The test object that has ended its test run.
23 * The time the test took.
25 protected function componentEndTest($test, $time) {
26 /** @var \PHPUnit\Framework\Test $test */
27 if (substr($test->toString(), 0, 22) == 'Drupal\Tests\Component') {
28 if ($test instanceof BrowserTestBase || $test instanceof KernelTestBase || $test instanceof UnitTestCase) {
29 $error = new AssertionFailedError('Component tests should not extend a core test base class.');
30 $test->getTestResultObject()->addFailure($test, $error, $time);