function PhpUnitApiFindAllClassFilesTest::testEquality

Checks that Drupal legacy and PHPUnit API based discoveries are equal.

File

core/tests/Drupal/KernelTests/Core/Test/PhpUnitApiFindAllClassFilesTest.php, line 31

Class

PhpUnitApiFindAllClassFilesTest
Tests ::findAllClassFiles() between TestDiscovery and PhpUnitTestDiscovery.

Namespace

Drupal\KernelTests\Core\Test

Code

public function testEquality(?string $extension = NULL, ?string $directory = NULL) : void {
    $testDiscovery = new TestDiscovery($this->container
        ->getParameter('app.root'), $this->container
        ->get('class_loader'));
    $internalList = $testDiscovery->findAllClassFiles($extension, $directory);
    // Location of PHPUnit configuration file.
    $configurationFilePath = $this->container
        ->getParameter('app.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';
    }
    $phpUnitTestDiscovery = new PhpUnitTestDiscovery($configurationFilePath);
    $phpUnitList = $phpUnitTestDiscovery->findAllClassFiles($extension, $directory);
    // Downgrade results to make them comparable, working around bugs and
    // additions.
    // 1. TestDiscovery discovers non-test classes that PHPUnit does not.
    $internalList = array_intersect_key($internalList, $phpUnitList);
    $this->assertEquals($internalList, $phpUnitList);
}

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