97bed4c7a8cddc7832dc8918f729eaa7f562271d
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.
14 public function testUnitTestFileNamesEndWithTest() {
15 // realpath() also normalizes directory separator on windows for prefix compares
16 $rootPath = realpath( __DIR__
. '/..' );
17 $suitesPath = realpath( __DIR__
. '/../suites/' );
18 $testClassRegex = implode( '|', [
22 'ApiQueryContinueTestBase',
23 'MediaWikiLangTestCase',
24 'MediaWikiMediaTestCase',
26 'ResourceLoaderTestCase',
27 'PHPUnit_Framework_TestCase',
28 '\\?PHPUnit\\Framework\\TestCase',
29 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement
31 'SpecialPageTestBase',
33 $testClassRegex = "/^class .* extends ($testClassRegex)/m";
35 $results = $this->recurseFiles( $rootPath );
37 $results = array_filter(
39 function ( $filename ) use ( $testClassRegex, $suitesPath ) {
40 // Remove testUnitTestFileNamesEndWithTest false positives
41 if ( strpos( $filename, $suitesPath ) === 0
42 ||
substr( $filename, -8 ) === 'Test.php'
46 $contents = file_get_contents( $filename );
47 return preg_match( $testClassRegex, $contents );
50 $strip = strlen( $rootPath ) +
1;
51 foreach ( $results as $k => $v ) {
52 $results[$k] = substr( $v, $strip );
57 "Unit test file in $rootPath must end with Test."
61 private function recurseFiles( $dir ) {
62 return ( new File_Iterator_Facade() )->getFilesAsArray( $dir, [ '.php' ] );