class TestDiscoveryTest
Same name and namespace in other branches
- 8.9.x core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php \Drupal\Tests\simpletest\Unit\TestDiscoveryTest
- 11.x core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php \Drupal\Tests\Core\Test\TestDiscoveryTest
- 10 core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php \Drupal\Tests\Core\Test\TestDiscoveryTest
- 9 core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php \Drupal\Tests\Core\Test\TestDiscoveryTest
- 8.9.x core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php \Drupal\Tests\Core\Test\TestDiscoveryTest
Unit tests for test discovery.
Attributes
#[CoversClass(PhpUnitTestDiscovery::class)]
#[CoversClass(TestDiscovery::class)]
#[Group('Test')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Test\TestDiscoveryTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of TestDiscoveryTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ TestDiscoveryTest.php, line 19
Namespace
Drupal\Tests\Core\TestView source
class TestDiscoveryTest extends UnitTestCase {
/**
* Tests test info parser.
*/
public function testTestInfoParser(array $expected, string $classname) : void {
$configurationFilePath = $this->root . \DIRECTORY_SEPARATOR . 'core';
$phpUnitTestDiscovery = PhpUnitTestDiscovery::instance()->setConfigurationFilePath($configurationFilePath);
$classes = $phpUnitTestDiscovery->getTestClasses(NULL, [
$expected['type'],
]);
$info = $classes[$expected['group']][$classname];
// The 'file' key varies depending on the CI build directory, but that's
// rather irrelevant here. Remove the key before comparison.
unset($info['file']);
$this->assertEquals($expected, $info);
}
public static function infoParserProvider() : array {
// A module provided unit test.
$tests[] = [
// Expected result.
[
'name' => TestDatabaseTest::class,
'group' => 'Test',
'groups' => [
'Test',
'simpletest',
'Template',
],
'description' => 'Tests Drupal\\Core\\Test\\TestDatabase.',
'type' => 'PHPUnit-Unit',
'tests_count' => 4,
],
// Classname.
TestDatabaseTest::class,
];
// A core unit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\\Tests\\Core\\DrupalTest',
'group' => 'DrupalTest',
'groups' => [
'DrupalTest',
],
'description' => 'Tests Drupal.',
'type' => 'PHPUnit-Unit',
'tests_count' => 34,
],
// Classname.
'Drupal\\Tests\\Core\\DrupalTest',
];
// A component unit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\\Tests\\Component\\Plugin\\PluginBaseTest',
'group' => 'Plugin',
'groups' => [
'Plugin',
],
'description' => 'Tests Drupal\\Component\\Plugin\\PluginBase.',
'type' => 'PHPUnit-Unit-Component',
'tests_count' => 7,
],
// Classname.
'Drupal\\Tests\\Component\\Plugin\\PluginBaseTest',
];
// Functional PHPUnit test.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\\FunctionalTests\\BrowserTestBaseTest',
'group' => 'browsertestbase',
'groups' => [
'browsertestbase',
],
'description' => 'Tests BrowserTestBase functionality.',
'type' => 'PHPUnit-Functional',
'tests_count' => 21,
],
// Classname.
'Drupal\\FunctionalTests\\BrowserTestBaseTest',
];
// Kernel PHPUnit test.
$tests['phpunit-kernel'] = [
// Expected result.
[
'name' => 'Drupal\\Tests\\file\\Kernel\\FileItemValidationTest',
'group' => 'file',
'groups' => [
'file',
],
'description' => 'Tests that files referenced in file and image fields are always validated.',
'type' => 'PHPUnit-Kernel',
'tests_count' => 2,
],
// Classname.
'Drupal\\Tests\\file\\Kernel\\FileItemValidationTest',
];
return $tests;
}
/**
* Tests for missing #[Group] attribute.
*/
public function testTestInfoParserMissingGroup() : void {
$this->expectException(MissingGroupException::class);
$this->expectExceptionMessage('Missing group metadata in test Drupal\\Tests\\Core\\Foo\\MissingAttributesTest::testNoMetadata');
$configurationFilePath = $this->root . \DIRECTORY_SEPARATOR . 'core';
$phpUnitTestDiscovery = PhpUnitTestDiscovery::instance()->setConfigurationFilePath($configurationFilePath);
$phpUnitTestDiscovery->getTestClasses(NULL, [], $this->root . \DIRECTORY_SEPARATOR . 'core/tests/fixtures/test_driver/MissingAttributesTest.php');
}
/**
* Tests for missing #[Group] attribute in a test with DataProvider.
*/
public function testTestInfoParserMissingGroupWithDataProvider() : void {
$this->expectException(MissingGroupException::class);
$this->expectExceptionMessage('Missing group metadata in test Drupal\\Tests\\Core\\Foo\\MissingAttributesWithDataProviderTest::testNoGroupMetadata#Test#1');
$configurationFilePath = $this->root . \DIRECTORY_SEPARATOR . 'core';
$phpUnitTestDiscovery = PhpUnitTestDiscovery::instance()->setConfigurationFilePath($configurationFilePath);
$phpUnitTestDiscovery->getTestClasses(NULL, [], $this->root . \DIRECTORY_SEPARATOR . 'core/tests/fixtures/test_driver/MissingAttributesWithDataProviderTest.php');
}
/**
* Tests PhpUnitTestDiscovery::getPhpunitTestSuite().
*/
public function testGetPhpunitTestSuite(string $classname, string|false $expected) : void {
$this->assertEquals($expected, PhpUnitTestDiscovery::getPhpunitTestSuite($classname));
}
public static function providerTestGetPhpunitTestSuite() : array {
$data = [];
$data['simpletest-web test'] = [
'\\Drupal\\rest\\Tests\\NodeTest',
FALSE,
];
$data['module-unittest'] = [
static::class,
'Unit',
];
$data['module-kernel test'] = [
'\\Drupal\\KernelTests\\Core\\Theme\\TwigMarkupInterfaceTest',
'Kernel',
];
$data['module-functional test'] = [
'\\Drupal\\FunctionalTests\\BrowserTestBaseTest',
'Functional',
];
$data['module-functional javascript test'] = [
'\\Drupal\\Tests\\toolbar\\FunctionalJavascript\\ToolbarIntegrationTest',
'FunctionalJavascript',
];
$data['core-unittest'] = [
'\\Drupal\\Tests\\ComposerIntegrationTest',
'Unit',
];
$data['core-unittest2'] = [
'Drupal\\Tests\\Core\\DrupalTest',
'Unit',
];
$data['core-script-test'] = [
'Drupal\\KernelTests\\Scripts\\TestSiteApplicationTest',
'Kernel',
];
$data['core-kernel test'] = [
'\\Drupal\\KernelTests\\KernelTestBaseTest',
'Kernel',
];
$data['core-functional test'] = [
'\\Drupal\\FunctionalTests\\ExampleTest',
'Functional',
];
$data['core-functional javascript test'] = [
'\\Drupal\\FunctionalJavascriptTests\\ExampleTest',
'FunctionalJavascript',
];
$data['core-build test'] = [
'\\Drupal\\BuildTests\\Framework\\Tests\\BuildTestTest',
'Build',
];
return $data;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| TestDiscoveryTest::infoParserProvider | public static | function | ||
| TestDiscoveryTest::providerTestGetPhpunitTestSuite | public static | function | ||
| TestDiscoveryTest::testGetPhpunitTestSuite | public | function | Tests PhpUnitTestDiscovery::getPhpunitTestSuite(). | |
| TestDiscoveryTest::testTestInfoParser | public | function | Tests test info parser. | |
| TestDiscoveryTest::testTestInfoParserMissingGroup | public | function | Tests for missing #[Group] attribute. | |
| TestDiscoveryTest::testTestInfoParserMissingGroupWithDataProvider | public | function | Tests for missing #[Group] attribute in a test with DataProvider. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | 355 | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.