Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TestCase.php

function TestCase::runBare

@internal This method is not covered by the backward compatibility promise for PHPUnit

Throws

Throwable

File

vendor/phpunit/phpunit/src/Framework/TestCase.php, line 647

Class

TestCase
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Namespace

PHPUnit\Framework

Code

public final function runBare() : void {
    $emitter = Event\Facade::emitter();
    $emitter->testPreparationStarted($this->valueObjectForEvents());
    $this->snapshotGlobalState();
    $this->startOutputBuffering();
    clearstatcache();
    $hookMethods = (new HookMethods())->hookMethods(static::class);
    $hasMetRequirements = false;
    $this->numberOfAssertionsPerformed = 0;
    $currentWorkingDirectory = getcwd();
    try {
        $this->checkRequirements();
        $hasMetRequirements = true;
        if ($this->inIsolation) {
            // @codeCoverageIgnoreStart
            $this->invokeBeforeClassHookMethods($hookMethods, $emitter);
            // @codeCoverageIgnoreEnd
        }
        if (method_exists(static::class, $this->name) && MetadataRegistry::parser()->forClassAndMethod(static::class, $this->name)
            ->isDoesNotPerformAssertions()
            ->isNotEmpty()) {
            $this->doesNotPerformAssertions = true;
        }
        $this->invokeBeforeTestHookMethods($hookMethods, $emitter);
        $this->invokePreConditionHookMethods($hookMethods, $emitter);
        $emitter->testPrepared($this->valueObjectForEvents());
        $this->wasPrepared = true;
        $this->testResult = $this->runTest();
        $this->verifyMockObjects();
        $this->invokePostConditionHookMethods($hookMethods, $emitter);
        $this->status = TestStatus::success();
    } catch (IncompleteTest $e) {
        $this->status = TestStatus::incomplete($e->getMessage());
        $emitter->testMarkedAsIncomplete($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e));
    } catch (SkippedTest $e) {
        $this->status = TestStatus::skipped($e->getMessage());
        $emitter->testSkipped($this->valueObjectForEvents(), $e->getMessage());
    } catch (AssertionError|AssertionFailedError $e) {
        if (!$this->wasPrepared) {
            $this->wasPrepared = true;
            $emitter->testPreparationFailed($this->valueObjectForEvents());
        }
        $this->status = TestStatus::failure($e->getMessage());
        $emitter->testFailed($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), Event\Code\ComparisonFailureBuilder::from($e));
    } catch (TimeoutException $e) {
        $this->status = TestStatus::risky($e->getMessage());
    } catch (Throwable $_e) {
        if ($this->isRegisteredFailure($_e)) {
            $this->status = TestStatus::failure($_e->getMessage());
            $emitter->testFailed($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($_e), null);
        }
        else {
            $e = $this->transformException($_e);
            $this->status = TestStatus::error($e->getMessage());
            $emitter->testErrored($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e));
        }
    }
    $outputBufferingStopped = false;
    if (!isset($e) && $this->hasExpectationOnOutput() && $this->stopOutputBuffering()) {
        $outputBufferingStopped = true;
        $this->performAssertionsOnOutput();
    }
    if ($this->status
        ->isSuccess()) {
        $emitter->testPassed($this->valueObjectForEvents());
        if (!$this->usesDataProvider()) {
            PassedTests::instance()->testMethodPassed($this->valueObjectForEvents(), $this->testResult);
        }
    }
    try {
        $this->mockObjects = [];
    } catch (Throwable $t) {
        Event\Facade::emitter()->testErrored($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($t));
    }
    // Tear down the fixture. An exception raised in tearDown() will be
    // caught and passed on when no exception was raised before.
    try {
        if ($hasMetRequirements) {
            $this->invokeAfterTestHookMethods($hookMethods, $emitter);
            if ($this->inIsolation) {
                // @codeCoverageIgnoreStart
                $this->invokeAfterClassHookMethods($hookMethods, $emitter);
                // @codeCoverageIgnoreEnd
            }
        }
    } catch (AssertionError|AssertionFailedError $e) {
        $this->status = TestStatus::failure($e->getMessage());
        $emitter->testFailed($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($e), Event\Code\ComparisonFailureBuilder::from($e));
    } catch (Throwable $exceptionRaisedDuringTearDown) {
        if (!isset($e)) {
            $this->status = TestStatus::error($exceptionRaisedDuringTearDown->getMessage());
            $e = $exceptionRaisedDuringTearDown;
            $emitter->testErrored($this->valueObjectForEvents(), Event\Code\ThrowableBuilder::from($exceptionRaisedDuringTearDown));
        }
    }
    if (!$outputBufferingStopped) {
        $this->stopOutputBuffering();
    }
    clearstatcache();
    if ($currentWorkingDirectory !== getcwd()) {
        chdir($currentWorkingDirectory);
    }
    $this->restoreGlobalState();
    $this->unregisterCustomComparators();
    $this->cleanupIniSettings();
    $this->cleanupLocaleSettings();
    libxml_clear_errors();
    $this->testValueObjectForEvents = null;
    if (isset($e)) {
        $this->onNotSuccessfulTest($e);
    }
}
RSS feed
Powered by Drupal