MediaWiki REL1_31
StructureTest.php
Go to the documentation of this file.
1<?php
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 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement
30 'DumpTestCase',
31 ] );
32 $testClassRegex = "^class .* extends ($testClassRegex)";
33 $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
34 " | xargs grep -El '$testClassRegex|function suite\‍('";
35
36 $results = null;
37 $exitCode = null;
38 exec( $finder, $results, $exitCode );
39
40 $this->assertEquals(
41 0,
42 $exitCode,
43 'Verify find/grep command succeeds.'
44 );
45
46 $results = array_filter(
47 $results,
48 [ $this, 'filterSuites' ]
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
66 public function filterSuites( $filename ) {
67 return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
68 }
69}
wfIsWindows()
Check if the operating system is Windows.
The tests here verify the structure of the code.
testUnitTestFileNamesEndWithTest()
Verify all files that appear to be tests have file names ending in Test.
filterSuites( $filename)
Filter to remove testUnitTestFileNamesEndWithTest false positives.