test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / structure / StructureTest.php
blobdf00d4df2290b6b6ebf523afa012c9b6b89e1890
1 <?php
2 /**
3 * The tests here verify the structure of the code. This is for outright bugs,
4 * not just style issues.
5 */
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
13 public function testUnitTestFileNamesEndWithTest() {
14 if ( wfIsWindows() ) {
15 $this->markTestSkipped( 'This test does not work on Windows' );
17 $rootPath = escapeshellarg( __DIR__ . '/..' );
18 $testClassRegex = implode( '|', array(
19 'ApiFormatTestBase',
20 'ApiTestCase',
21 'ApiQueryTestBase',
22 'ApiQueryContinueTestBase',
23 'MediaWikiLangTestCase',
24 'MediaWikiTestCase',
25 'PHPUnit_Framework_TestCase',
26 'DumpTestCase',
27 ) );
28 $testClassRegex = "^class .* extends ($testClassRegex)";
29 $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
30 " | xargs grep -El '$testClassRegex|function suite\('";
32 $results = null;
33 $exitCode = null;
34 exec( $finder, $results, $exitCode );
36 $this->assertEquals(
38 $exitCode,
39 'Verify find/grep command succeeds.'
42 $results = array_filter(
43 $results,
44 array( $this, 'filterSuites' )
46 $strip = strlen( $rootPath ) - 1;
47 foreach ( $results as $k => $v ) {
48 $results[$k] = substr( $v, $strip );
50 $this->assertEquals(
51 array(),
52 $results,
53 "Unit test file in $rootPath must end with Test."
57 /**
58 * Filter to remove testUnitTestFileNamesEndWithTest false positives.
60 public function filterSuites( $filename ) {
61 return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;