Merge "Title: Refactor JS/CSS page handling to be more sane"
[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 */
13 public function testUnitTestFileNamesEndWithTest() {
14 if ( wfIsWindows() ) {
15 $this->markTestSkipped( 'This test does not work on Windows' );
16 }
17 $rootPath = escapeshellarg( __DIR__ . '/..' );
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 'DumpTestCase',
30 ] );
31 $testClassRegex = "^class .* extends ($testClassRegex)";
32 $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
33 " | xargs grep -El '$testClassRegex|function suite\('";
34
35 $results = null;
36 $exitCode = null;
37 exec( $finder, $results, $exitCode );
38
39 $this->assertEquals(
40 0,
41 $exitCode,
42 'Verify find/grep command succeeds.'
43 );
44
45 $results = array_filter(
46 $results,
47 [ $this, 'filterSuites' ]
48 );
49 $strip = strlen( $rootPath ) - 1;
50 foreach ( $results as $k => $v ) {
51 $results[$k] = substr( $v, $strip );
52 }
53 $this->assertEquals(
54 [],
55 $results,
56 "Unit test file in $rootPath must end with Test."
57 );
58 }
59
60 /**
61 * Filter to remove testUnitTestFileNamesEndWithTest false positives.
62 * @param string $filename
63 * @return bool
64 */
65 public function filterSuites( $filename ) {
66 return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
67 }
68 }