Since the latter is going to be removed, make sure that the former has everything we need. In particular: - Add failOnRisky=true from suite.xml - Reorder config options and add comment about stderr from suite.xml - Remove non-existent tests/phpunit/skins and tests/phpunit/documentation from the test suites. These cause an error when trying to run all the suites with `composer phpunit`. - Leave the other suites as they are. Compared to suite.xml, phpunit.xml.dist has separate suites for core, extensions, and skins unit tests. - Leave includeUncoveredFiles to false. The rationale in I3d19627fa36f6cc6666c29fdb638272fdaa30630 seems convincing. CI already sets it to true: https://w.wiki/72qE - Leave slowThreshold to 100 as per Ia6ed404d4d4cc8a7b4b8a48b232f644f400f8103. I believe that change simply missed suite.xml. The same rationale that led to the threshold being increased for unit tests is valid a fortiori for integration tests, which are generally slower. Rename SuiteDirectoryTest and make it check phpunit.xml.dist too. Bug: T227900 Change-Id: Ib4b47b337870dffc61dd44817a21d11809075d5b
116 lines
2.9 KiB
PHP
116 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* The tests here verify that phpunit/suite.xml covers all of the tests under /tests/phpunit
|
|
* @group medium
|
|
* @coversNothing
|
|
*/
|
|
class PHPUnitConfigTest extends PHPUnit\Framework\TestCase {
|
|
|
|
/**
|
|
* @dataProvider provideConfigFiles
|
|
*/
|
|
public function testConfigDirectories( string $configPath ) {
|
|
// realpath() also normalizes directory separator on windows for prefix compares
|
|
$testRootDir = realpath( __DIR__ . '/..' );
|
|
|
|
$dom = new DOMDocument();
|
|
$dom->load( $configPath );
|
|
/** @var DOMElement $suites */
|
|
$suites = $dom->documentElement->getElementsByTagName( 'testsuites' )[0];
|
|
|
|
$suiteInfos = [];
|
|
/** @var DOMElement $suite */
|
|
foreach ( $suites->getElementsByTagName( 'testsuite' ) as $suite ) {
|
|
$generalDirs = [];
|
|
foreach ( $suite->getElementsByTagName( 'directory' ) as $dirNode ) {
|
|
$generalDirs[] = str_replace( 'tests/phpunit/', '', $dirNode->textContent );
|
|
}
|
|
$excludedDirs = [];
|
|
foreach ( $suite->getElementsByTagName( 'exclude' ) as $dirNode ) {
|
|
$excludedDirs[] = str_replace( 'tests/phpunit/', '', $dirNode->textContent );
|
|
}
|
|
$suiteInfos[$suite->getAttribute( 'name' )] = [ $generalDirs, $excludedDirs ];
|
|
}
|
|
|
|
$directoriesFound = scandir( $testRootDir, SCANDIR_SORT_ASCENDING );
|
|
if ( !$directoriesFound ) {
|
|
$this->fail( "Could not scan '$testRootDir' directory" );
|
|
}
|
|
|
|
$directoriesNeeded = array_values( array_diff(
|
|
array_filter(
|
|
$directoriesFound,
|
|
static function ( $name ) use ( $testRootDir ) {
|
|
return (
|
|
$name !== '.' &&
|
|
$name !== '..' &&
|
|
is_dir( "$testRootDir/$name" )
|
|
);
|
|
}
|
|
),
|
|
[
|
|
'data',
|
|
'docs',
|
|
'documentation',
|
|
'mocks',
|
|
'suites' // custom suite entry points load their own files
|
|
]
|
|
) );
|
|
|
|
$directoriesIncluded = [];
|
|
foreach ( $directoriesNeeded as $directory ) {
|
|
if ( $this->isDirectoryIncluded( $directory, $suiteInfos ) ) {
|
|
$directoriesIncluded[] = $directory;
|
|
}
|
|
}
|
|
|
|
$this->assertSame(
|
|
$directoriesNeeded,
|
|
$directoriesIncluded,
|
|
"All suites included"
|
|
);
|
|
}
|
|
|
|
public static function provideConfigFiles(): array {
|
|
return [
|
|
'suite.xml' => [ __DIR__ . '/../suite.xml' ],
|
|
'phpunit.xml.dist' => [ __DIR__ . '/../../../phpunit.xml.dist' ],
|
|
];
|
|
}
|
|
|
|
private function isDirectoryIncluded( $dir, array $suiteInfos ) {
|
|
foreach ( $suiteInfos as [ $generalDirs, $excludedDirs ] ) {
|
|
$found = false;
|
|
foreach ( $generalDirs as $generalDir ) {
|
|
if ( $this->isSameOrChildOfDirectory( $dir, $generalDir ) ) {
|
|
$found = true;
|
|
break;
|
|
}
|
|
}
|
|
foreach ( $excludedDirs as $excludedDir ) {
|
|
if ( $this->isSameOrChildOfDirectory( $dir, $excludedDir ) ) {
|
|
$found = false;
|
|
break;
|
|
}
|
|
}
|
|
if ( $found ) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function isSameOrChildOfDirectory( $dirA, $dirB ) {
|
|
if ( $dirA === $dirB ) {
|
|
return true;
|
|
}
|
|
|
|
if ( strpos( "$dirB/", $dirA ) === 0 ) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|