More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Listeners / DrupalComponentTestListenerTrait.php
1 <?php
2
3 namespace Drupal\Tests\Listeners;
4
5 use Drupal\KernelTests\KernelTestBase;;
6 use Drupal\Tests\BrowserTestBase;;
7 use Drupal\Tests\UnitTestCase;
8 use PHPUnit\Framework\AssertionFailedError;
9
10 /**
11  * Ensures that no component tests are extending a core test base class.
12  *
13  * @internal
14  */
15 trait DrupalComponentTestListenerTrait {
16
17   /**
18    * Reacts to the end of a test.
19    *
20    * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test
21    *   The test object that has ended its test run.
22    * @param float $time
23    *   The time the test took.
24    */
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);
31       }
32     }
33   }
34
35 }