function DrupalListener::endTest

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit6/DrupalListener.php \Drupal\TestTools\PhpUnitCompatibility\PhpUnit6\DrupalListener::endTest()
  2. 8.9.x core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit7/DrupalListener.php \Drupal\TestTools\PhpUnitCompatibility\PhpUnit7\DrupalListener::endTest()
  3. 10 core/tests/Drupal/Tests/Listeners/DrupalListener.php \Drupal\Tests\Listeners\DrupalListener::endTest()
  4. 11.x core/tests/Drupal/Tests/Listeners/DrupalListener.php \Drupal\Tests\Listeners\DrupalListener::endTest()

File

core/tests/Drupal/Tests/Listeners/DrupalListener.php, line 114

Class

DrupalListener
Listens to PHPUnit test runs.

Namespace

Drupal\Tests\Listeners

Code

public function endTest(Test $test, float $time) : void {
    if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
        $className = get_class($test);
        $groups = UtilTest::getGroups($className, $test->getName(FALSE));
        if (in_array('legacy', $groups, TRUE)) {
            // If the Symfony listener is not registered for legacy tests then
            // deprecations triggered by the DebugClassloader in
            // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
            // are not correctly identified as occurring in legacy tests.
            $symfony_error_handler = set_error_handler([
                SymfonyTestsListenerTrait::class,
                'handleError',
            ]);
        }
    }
    $this->deprecationEndTest($test, $time);
    $this->symfonyListener
        ->endTest($test, $time);
    $this->componentEndTest($test, $time);
    $this->standardsEndTest($test, $time);
    if (isset($symfony_error_handler)) {
        // If this test listener has added the Symfony error handler then it needs
        // to be removed.
        restore_error_handler();
    }
    // The Drupal error handler has to be removed after the Symfony error
    // handler is potentially removed in
    // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest().
    $this->removeErrorHandler();
}

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