trait DrupalComponentTestListenerTrait

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php \Drupal\Tests\Listeners\DrupalComponentTestListenerTrait
  2. 10 core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php \Drupal\Tests\Listeners\DrupalComponentTestListenerTrait
  3. 11.x core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php \Drupal\Tests\Listeners\DrupalComponentTestListenerTrait

Ensures that no component tests are extending a core test base class.

@internal

Hierarchy

File

core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php, line 15

Namespace

Drupal\Tests\Listeners
View source
trait DrupalComponentTestListenerTrait {
    
    /**
     * Reacts to the end of a test.
     *
     * @param \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);
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
DrupalComponentTestListenerTrait::componentEndTest protected function Reacts to the end of a test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.