function TestDiscoveryTest::testTestInfoParser

Tests test info parser.

@legacy-covers ::getTestInfo

Attributes

#[DataProvider('infoParserProvider')] #[RunInSeparateProcess]

File

core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php, line 36

Class

TestDiscoveryTest
Unit tests for TestDiscovery.

Namespace

Drupal\Tests\Core\Test

Code

public function testTestInfoParser($expected, $classname, $doc_comment = NULL) : void {
  try {
    $info = TestDiscovery::getTestInfo($classname, $doc_comment);
    $this->assertEquals($expected, $info);
  } catch (MissingGroupException) {
    // In case the test class was converted to attributes already, we need to
    // get the data from PHPUnit discovery instead.
    $configurationFilePath = $this->root . \DIRECTORY_SEPARATOR . 'core';
    $phpUnitTestDiscovery = PhpUnitTestDiscovery::instance()->setConfigurationFilePath($configurationFilePath);
    $classes = $phpUnitTestDiscovery->getTestClasses(NULL, [
      $expected['type'],
    ]);
    $info = $classes[$expected['group']][$classname];
    // The 'file' and 'tests_count' keys are additional in PHPUnit, and the
    // computed 'description' key may differ, but that's irrelevant. Remove
    // the keys before comparison.
    unset($info['file'], $info['tests_count'], $info['description'], $expected['description']);
    $this->assertEquals($expected, $info);
  }
}

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