function PhpUnitTestDiscoveryTest::testPhpUnitTestDiscoveryEqualsInternal
Tests equality of test discovery between run-tests.sh and PHPUnit CLI.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Test/ PhpUnitTestDiscoveryTest.php, line 64
Class
- PhpUnitTestDiscoveryTest
- Tests equality of test discovery between run-tests.sh and PHPUnit CLI.
Namespace
Drupal\KernelTests\Core\TestCode
public function testPhpUnitTestDiscoveryEqualsInternal() : void {
// Drupal's test discovery, used by run-tests.sh.
$testDiscovery = new TestDiscovery($this->container
->getParameter('app.root'), $this->container
->get('class_loader'));
$internalList = [];
foreach ($testDiscovery->getTestClasses() as $group) {
foreach (array_keys($group) as $class) {
$internalList[] = $class;
}
}
$internalList = array_unique($internalList);
asort($internalList);
// Location of PHPUnit configuration file.
$configurationFilePath = $this->root . \DIRECTORY_SEPARATOR . 'core';
// @todo once PHPUnit 10 is no longer used, remove the condition.
// @see https://www.drupal.org/project/drupal/issues/3497116
if (RunnerVersion::getMajor() >= 11) {
$configurationFilePath .= \DIRECTORY_SEPARATOR . '.phpunit-next.xml';
}
// PHPUnit's test discovery - via CLI execution.
$process = new Process([
'vendor/bin/phpunit',
'--configuration',
$configurationFilePath,
'--list-tests-xml',
$this->xmlOutputFile,
], $this->root);
$process->setTimeout(300)
->setIdleTimeout(300)
->run();
$this->assertEquals(0, $process->getExitCode(), 'COMMAND: ' . $process->getCommandLine() . "\n" . 'OUTPUT: ' . $process->getOutput() . "\n" . 'ERROR: ' . $process->getErrorOutput() . "\n");
$phpUnitXmlList = new \DOMDocument();
$phpUnitXmlList->loadXML(file_get_contents($this->xmlOutputFile));
$phpUnitClientList = [];
// Try PHPUnit 10 format first.
// @todo remove once PHPUnit 10 is no longer used.
foreach ($phpUnitXmlList->getElementsByTagName('testCaseClass') as $node) {
$phpUnitClientList[] = $node->getAttribute('name');
}
// If empty, try PHPUnit 11+ format.
if (empty($phpUnitClientList)) {
foreach ($phpUnitXmlList->getElementsByTagName('testClass') as $node) {
$phpUnitClientList[] = $node->getAttribute('name');
}
}
asort($phpUnitClientList);
// Check against Drupal's discovery.
$this->assertEquals(implode("\n", $phpUnitClientList), implode("\n", $internalList), self::TEST_LIST_MISMATCH_MESSAGE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.