4 * The tests here verify that phpunit/suite.xml covers all of the tests under /tests/phpunit
8 class PHPUnitConfigTest
extends PHPUnit\Framework\TestCase
{
11 * @dataProvider provideConfigFiles
13 public function testConfigDirectories( string $configPath ) {
14 // realpath() also normalizes directory separator on windows for prefix compares
15 $testRootDir = realpath( __DIR__
. '/..' );
17 $dom = new DOMDocument();
18 $dom->load( $configPath );
19 /** @var DOMElement $suites */
20 $suites = $dom->documentElement
->getElementsByTagName( 'testsuites' )[0];
23 /** @var DOMElement $suite */
24 foreach ( $suites->getElementsByTagName( 'testsuite' ) as $suite ) {
26 foreach ( $suite->getElementsByTagName( 'directory' ) as $dirNode ) {
27 $generalDirs[] = str_replace( 'tests/phpunit/', '', $dirNode->textContent
);
30 foreach ( $suite->getElementsByTagName( 'exclude' ) as $dirNode ) {
31 $excludedDirs[] = str_replace( 'tests/phpunit/', '', $dirNode->textContent
);
33 $suiteInfos[$suite->getAttribute( 'name' )] = [ $generalDirs, $excludedDirs ];
36 $directoriesFound = scandir( $testRootDir, SCANDIR_SORT_ASCENDING
);
37 if ( !$directoriesFound ) {
38 $this->fail( "Could not scan '$testRootDir' directory" );
41 $directoriesNeeded = array_values( array_diff(
44 static function ( $name ) use ( $testRootDir ) {
48 is_dir( "$testRootDir/$name" )
57 'suites' // custom suite entry points load their own files
61 $directoriesIncluded = [];
62 foreach ( $directoriesNeeded as $directory ) {
63 if ( $this->isDirectoryIncluded( $directory, $suiteInfos ) ) {
64 $directoriesIncluded[] = $directory;
75 public static function provideConfigFiles(): array {
77 'suite.xml' => [ __DIR__
. '/../suite.xml' ],
78 'phpunit.xml.dist' => [ __DIR__
. '/../../../phpunit.xml.dist' ],
82 private function isDirectoryIncluded( $dir, array $suiteInfos ) {
83 foreach ( $suiteInfos as [ $generalDirs, $excludedDirs ] ) {
85 foreach ( $generalDirs as $generalDir ) {
86 if ( $this->isSameOrChildOfDirectory( $dir, $generalDir ) ) {
91 foreach ( $excludedDirs as $excludedDir ) {
92 if ( $this->isSameOrChildOfDirectory( $dir, $excludedDir ) ) {
105 private function isSameOrChildOfDirectory( $dirA, $dirB ) {
106 if ( $dirA === $dirB ) {
110 if ( str_starts_with( "$dirB/", $dirA ) ) {