function AssertPreconditionsTrait::failIfUnmetPreConditions

Asserts universal test preconditions before any setup is done.

If these preconditions aren't met, automated tests will absolutely fail needlessly with misleading errors. In that case, there's no reason to even begin.

Ordinarily, these preconditions would be asserted in ::assertPreConditions(), which PHPUnit provides for exactly this use case. Unfortunately, that method doesn't run until after ::setUp(), so our (many) tests with expensive, time-consuming setup routines wouldn't actually fail very early.

Parameters

string $when: Either 'before' (before any test methods run) or 'after' (after any test method finishes).

See also

\PHPUnit\Framework\TestCase::assertPreConditions()

\PHPUnit\Framework\TestCase::setUpBeforeClass()

self::setupBeforeClass()

self::tearDown()

2 calls to AssertPreconditionsTrait::failIfUnmetPreConditions()
AssertPreconditionsTrait::setUpBeforeClass in core/modules/package_manager/tests/src/Traits/AssertPreconditionsTrait.php
Invokes the test preconditions assertion before the first test is run.
AssertPreconditionsTrait::tearDown in core/modules/package_manager/tests/src/Traits/AssertPreconditionsTrait.php
Invokes the test preconditions assertion after each test run.

File

core/modules/package_manager/tests/src/Traits/AssertPreconditionsTrait.php, line 60

Class

AssertPreconditionsTrait
Asserts preconditions for tests to function properly.

Namespace

Drupal\Tests\package_manager\Traits

Code

protected static function failIfUnmetPreConditions(string $when) : void {
    assert(in_array($when, [
        'before',
        'after',
    ], TRUE));
    static::assertNoFailureMarker($when);
}

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