TestRequirementsTrait.php

Same filename in other branches
  1. 9 core/tests/Drupal/Tests/TestRequirementsTrait.php
  2. 8.9.x core/tests/Drupal/Tests/TestRequirementsTrait.php
  3. 10 core/tests/Drupal/Tests/TestRequirementsTrait.php

Namespace

Drupal\Tests

File

core/tests/Drupal/Tests/TestRequirementsTrait.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests;


/**
 * Allows test classes to require Drupal modules as dependencies.
 *
 * This trait is assumed to be on a subclass of \PHPUnit\Framework\TestCase, and
 * overrides \PHPUnit\Framework\TestCase::checkRequirements(). This allows the
 * test to be marked as skipped before any kernel boot processes have happened.
 */
trait TestRequirementsTrait {
    
    /**
     * Returns the Drupal root directory.
     *
     * @return string
     */
    protected static function getDrupalRoot() : string {
        return dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
    }

}

Traits

Title Deprecated Summary
TestRequirementsTrait Allows test classes to require Drupal modules as dependencies.

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