MediaWiki REL1_33
StructureTest.php
Go to the documentation of this file.
1<?php
15 // realpath() also normalizes directory separator on windows for prefix compares
16 $rootPath = realpath( __DIR__ . '/..' );
17 $suitesPath = realpath( __DIR__ . '/../suites/' );
18 $testClassRegex = implode( '|', [
19 'ApiFormatTestBase',
20 'ApiTestCase',
21 'ApiQueryTestBase',
22 'ApiQueryContinueTestBase',
23 'MediaWikiLangTestCase',
24 'MediaWikiMediaTestCase',
25 'MediaWikiTestCase',
26 'ResourceLoaderTestCase',
27 'PHPUnit_Framework_TestCase',
28 '\\?PHPUnit\\Framework\\TestCase',
29 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement
30 'DumpTestCase',
31 'SpecialPageTestBase',
32 ] );
33 $testClassRegex = "/^class .* extends ($testClassRegex)/m";
34
35 $results = $this->recurseFiles( $rootPath );
36
37 $results = array_filter(
38 $results,
39 function ( $filename ) use ( $testClassRegex, $suitesPath ) {
40 // Remove testUnitTestFileNamesEndWithTest false positives
41 if ( strpos( $filename, $suitesPath ) === 0
42 || substr( $filename, -8 ) === 'Test.php'
43 ) {
44 return false;
45 }
46 $contents = file_get_contents( $filename );
47 return preg_match( $testClassRegex, $contents );
48 }
49 );
50 $strip = strlen( $rootPath ) + 1;
51 foreach ( $results as $k => $v ) {
52 $results[$k] = substr( $v, $strip );
53 }
54 $this->assertEquals(
55 [],
56 $results,
57 "Unit test file in $rootPath must end with Test."
58 );
59 }
60
61 private function recurseFiles( $dir ) {
62 return ( new File_Iterator_Facade() )->getFilesAsArray( $dir, [ '.php' ] );
63 }
64}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
The tests here verify the structure of the code.
testUnitTestFileNamesEndWithTest()
Verify all files that appear to be tests have file names ending in Test.