class DrupalTestCase
Same name and namespace in other branches
- 7.x modules/simpletest/drupal_web_test_case.php \DrupalTestCase
Provides the root base class for all Drupal core tests.
Hierarchy
- class \Drupal\Tests\DrupalTestCase uses \Drupal\Tests\DrupalTestCaseTrait extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of DrupalTestCase
Related topics
3 files declare their use of DrupalTestCase
- BuildTestBase.php in core/
tests/ Drupal/ BuildTests/ Framework/ BuildTestBase.php - KernelTestBase.php in core/
tests/ Drupal/ KernelTests/ KernelTestBase.php - TestSetupTraitTest.php in core/
tests/ Drupal/ Tests/ Core/ Test/ TestSetupTraitTest.php
File
-
core/
tests/ Drupal/ Tests/ DrupalTestCase.php, line 15
Namespace
Drupal\TestsView source
abstract class DrupalTestCase extends TestCase {
use DrupalTestCaseTrait;
/**
* The Drupal root directory.
*/
protected string $root;
/**
* Ensure that the $root property is set initially.
*
* This is run with a high priority since other test setup code that runs in
* #[Before] hooks or setUp() requires access to $root.
*
* @internal
*/
final protected function setUpRoot() : void {
if (isset($this->root)) {
throw new \LogicException("setUpRoot should be called exactly once by PHPUnit's Before test hook and root overrides should happen after.");
}
$this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
}
/**
* Returns the Drupal root directory.
*
* @return string
* The Drupal root directory.
*
* @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Access
* $this->root directly.
*
* @see https://www.drupal.org/node/3574112
*/
protected function getDrupalRoot() : string {
@trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Access $this->root directly. See https://www.drupal.org/node/3574112', E_USER_DEPRECATED);
return dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.