Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / structure / StructureTest.php
blob2554516325a4d80743b5f69c8ca9ecfb3e187228
1 <?php
3 use SebastianBergmann\FileIterator\Facade;
5 /**
6 * The tests here verify the structure of the code. This is for outright bugs,
7 * not just style issues.
8 * @coversNothing
9 */
10 class StructureTest extends \PHPUnit\Framework\TestCase {
11 /**
12 * Verify all files that appear to be tests have file names ending in
13 * Test. If the file names do not end in Test, they will not be run.
14 * @group medium
16 public function testUnitTestFileNamesEndWithTest() {
17 // realpath() also normalizes directory separator on windows for prefix compares
18 $rootPath = realpath( __DIR__ . '/..' );
19 $suitesPath = realpath( __DIR__ . '/../suites/' );
20 $testClassRegex = '/^(final )?class .* extends [\S]*(TestCase|TestBase)\\b/m';
22 $results = $this->recurseFiles( $rootPath );
24 $results = array_filter(
25 $results,
26 static function ( $filename ) use ( $testClassRegex, $suitesPath ) {
27 // Remove testUnitTestFileNamesEndWithTest false positives
28 if ( str_starts_with( $filename, $suitesPath ) ||
29 str_ends_with( $filename, 'Test.php' )
30 ) {
31 return false;
33 $contents = file_get_contents( $filename );
34 return preg_match( $testClassRegex, $contents );
37 $strip = strlen( $rootPath ) + 1;
38 foreach ( $results as $k => $v ) {
39 $results[$k] = substr( $v, $strip );
42 // Normalize indexes to make failure output less confusing
43 $results = array_values( $results );
45 $this->assertEquals(
46 [],
47 $results,
48 "Unit test file in $rootPath must end with Test."
52 private function recurseFiles( $dir ) {
53 return ( new Facade() )->getFilesAsArray( $dir, [ '.php' ] );