3 * The tests here verify the structure of the code. This is for outright bugs,
4 * not just style issues.
7 class StructureTest
extends MediaWikiTestCase
{
9 * Verify all files that appear to be tests have file names ending in
10 * Test. If the file names do not end in Test, they will not be run.
13 public function testUnitTestFileNamesEndWithTest() {
14 // realpath() also normalizes directory separator on windows for prefix compares
15 $rootPath = realpath( __DIR__
. '/..' );
16 $suitesPath = realpath( __DIR__
. '/../suites/' );
17 $testClassRegex = implode( '|', [
21 'ApiQueryContinueTestBase',
22 'MediaWikiLangTestCase',
23 'MediaWikiMediaTestCase',
25 'ResourceLoaderTestCase',
26 'PHPUnit_Framework_TestCase',
27 '\\?PHPUnit\\Framework\\TestCase',
28 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement
30 'SpecialPageTestBase',
32 $testClassRegex = "/^class .* extends ($testClassRegex)/m";
34 $results = $this->recurseFiles( $rootPath );
36 $results = array_filter(
38 function ( $filename ) use ( $testClassRegex, $suitesPath ) {
39 // Remove testUnitTestFileNamesEndWithTest false positives
40 if ( strpos( $filename, $suitesPath ) === 0
41 ||
substr( $filename, -8 ) === 'Test.php'
45 $contents = file_get_contents( $filename );
46 return preg_match( $testClassRegex, $contents );
49 $strip = strlen( $rootPath ) +
1;
50 foreach ( $results as $k => $v ) {
51 $results[$k] = substr( $v, $strip );
56 "Unit test file in $rootPath must end with Test."
60 private function recurseFiles( $dir ) {
61 return ( new File_Iterator_Facade() )->getFilesAsArray( $dir, [ '.php' ] );