* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
* tests/phpunit/phpunit.php is retained but will be removed after CI
jobs and other references on
codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
are removed
* add a default bootstrap.integration.php; unit tests in
composer.json use the non-MW bootstrap file (bootstrap.php)
* Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php
Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
110 lines
2.6 KiB
PHP
110 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* The tests here verify that phpunit.xml.dist covers all of the tests under /tests/phpunit
|
|
* @group medium
|
|
*/
|
|
class SuiteDirectoryTest extends PHPUnit\Framework\TestCase {
|
|
|
|
/**
|
|
* @coversNothing
|
|
*/
|
|
public function testSuiteXmlDirectories() {
|
|
// realpath() also normalizes directory separator on windows for prefix compares
|
|
$rootPath = realpath( __DIR__ . '/' );
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
$ip = dirname( __DIR__, 3 );
|
|
$dom->load( "$ip/phpunit.xml.dist" );
|
|
/** @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[] = $dirNode->textContent;
|
|
}
|
|
$excludedDirs = [];
|
|
foreach ( $suite->getElementsByTagName( 'exclude' ) as $dirNode ) {
|
|
$excludedDirs[] = $dirNode->textContent;
|
|
}
|
|
$suiteInfos[$suite->getAttribute( 'name' )] = [ $generalDirs, $excludedDirs ];
|
|
}
|
|
|
|
$directoriesFound = scandir( $rootPath, SCANDIR_SORT_ASCENDING );
|
|
if ( !$directoriesFound ) {
|
|
$this->fail( "Could not scan '$rootPath' directory" );
|
|
}
|
|
|
|
$directoriesNeeded = array_values( array_diff(
|
|
array_filter(
|
|
$directoriesFound,
|
|
static function ( $name ) use ( $rootPath ) {
|
|
return (
|
|
$name !== '.' &&
|
|
$name !== '..' &&
|
|
is_dir( "$rootPath/$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"
|
|
);
|
|
}
|
|
|
|
private function isDirectoryIncluded( $dir, array $suiteInfos ) {
|
|
foreach ( $suiteInfos as list( $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;
|
|
}
|
|
}
|