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 55

Class

PhpUnitTestDiscoveryTest
Tests equality of test discovery between run-tests.sh and PHPUnit CLI.

Namespace

Drupal\KernelTests\Core\Test

Code

public function testPhpUnitTestDiscoveryEqualsInternal() : void {
    // PHPUnit's own test discovery.
    $process = new Process([
        'vendor/bin/phpunit',
        '--configuration',
        'core',
        '--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));
    $phpUnitList = [];
    foreach ($phpUnitXmlList->getElementsByTagName('testCaseClass') as $node) {
        $phpUnitList[] = $node->getAttribute('name');
    }
    asort($phpUnitList);
    // Drupal's own 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);
    $this->assertEquals(array_values($phpUnitList), array_values($internalList));
}

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