Merge "Hide TOC with CSS instead of JavaScript"
[lhc/web/wiklou.git] / tests / phpunit / structure / StructureTest.php
1 <?php
2 /**
3 * The tests here verify the structure of the code. This is for outright bugs,
4 * not just style issues.
5 */
6
7 class StructureTest extends MediaWikiTestCase {
8 /**
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.
11 * @group medium
12 * @coversNothing
13 */
14 public function testUnitTestFileNamesEndWithTest() {
15 if ( wfIsWindows() ) {
16 $this->markTestSkipped( 'This test does not work on Windows' );
17 }
18 $rootPath = escapeshellarg( __DIR__ . '/..' );
19 $testClassRegex = implode( '|', [
20 'ApiFormatTestBase',
21 'ApiTestCase',
22 'ApiQueryTestBase',
23 'ApiQueryContinueTestBase',
24 'MediaWikiLangTestCase',
25 'MediaWikiMediaTestCase',
26 'MediaWikiTestCase',
27 'ResourceLoaderTestCase',
28 'PHPUnit_Framework_TestCase',
29 '\\?PHPUnit\\Framework\\TestCase',
30 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement
31 'DumpTestCase',
32 ] );
33 $testClassRegex = "^class .* extends ($testClassRegex)";
34 $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
35 " | xargs grep -El '$testClassRegex|function suite\('";
36
37 $results = null;
38 $exitCode = null;
39 exec( $finder, $results, $exitCode );
40
41 $this->assertEquals(
42 0,
43 $exitCode,
44 'Verify find/grep command succeeds.'
45 );
46
47 $results = array_filter(
48 $results,
49 [ $this, 'filterSuites' ]
50 );
51 $strip = strlen( $rootPath ) - 1;
52 foreach ( $results as $k => $v ) {
53 $results[$k] = substr( $v, $strip );
54 }
55 $this->assertEquals(
56 [],
57 $results,
58 "Unit test file in $rootPath must end with Test."
59 );
60 }
61
62 /**
63 * Filter to remove testUnitTestFileNamesEndWithTest false positives.
64 * @param string $filename
65 * @return bool
66 */
67 public function filterSuites( $filename ) {
68 return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
69 }
70 }