class BrowserTestBaseTest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php \Drupal\KernelTests\Core\Test\BrowserTestBaseTest

@group Test @group FunctionalTests @group legacy

@coversDefaultClass \Drupal\Tests\BrowserTestBase

Hierarchy

Expanded class hierarchy of BrowserTestBaseTest

File

core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php, line 19

Namespace

Drupal\KernelTests\Core\Test
View source
class BrowserTestBaseTest extends KernelTestBase {
  
  /**
   * Tests that a test method is skipped when it requires a module not present.
   *
   * In order to catch checkRequirements() regressions, we have to make a new
   * test object and run checkRequirements() here.
   *
   * @covers ::checkRequirements
   * @covers ::checkModuleRequirements
   */
  public function testMethodRequiresModule() : void {
    $this->expectDeprecation('Drupal\\Tests\\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
    require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleMethodTest.php';
    // @phpstan-ignore-next-line
    $stub_test = new BrowserMissingDependentModuleMethodTest();
    // We have to setName() to the method name we're concerned with.
    $stub_test->setName('testRequiresModule');
    // We cannot use $this->setExpectedException() because PHPUnit would skip
    // the test before comparing the exception type.
    try {
      $stub_test->publicCheckRequirements();
      $this->fail('Missing required module throws skipped test exception.');
    } catch (SkippedTestError $e) {
      $this->assertEquals('Required modules: module_does_not_exist', $e->getMessage());
    }
  }
  
  /**
   * Tests that a test case is skipped when it requires a module not present.
   *
   * In order to catch checkRequirements() regressions, we have to make a new
   * test object and run checkRequirements() here.
   *
   * @covers ::checkRequirements
   * @covers ::checkModuleRequirements
   */
  public function testRequiresModule() : void {
    $this->expectDeprecation('Drupal\\Tests\\TestRequirementsTrait::checkModuleRequirements() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3418480');
    require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleTest.php';
    // @phpstan-ignore-next-line
    $stub_test = new BrowserMissingDependentModuleTest();
    // We have to setName() to the method name we're concerned with.
    $stub_test->setName('testRequiresModule');
    // We cannot use $this->setExpectedException() because PHPUnit would skip
    // the test before comparing the exception type.
    try {
      $stub_test->publicCheckRequirements();
      $this->fail('Missing required module throws skipped test exception.');
    } catch (SkippedTestError $e) {
      $this->assertEquals('Required modules: module_does_not_exist', $e->getMessage());
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
BrowserTestBaseTest::testMethodRequiresModule public function Tests that a test method is skipped when it requires a module not present.
BrowserTestBaseTest::testRequiresModule public function Tests that a test case is skipped when it requires a module not present.
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.

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