Follow-up r104051: fix tests
[lhc/web/wiklou.git] / tests / phpunit / 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 */
12 public function testUnitTestFileNamesEndWithTest() {
13 if ( wfIsWindows() ) {
14 $this->markTestSkipped( 'This test does not work on Windows' );
15 }
16 $rootPath = escapeshellarg( __DIR__ );
17 $testClassRegex = implode( '|', array(
18 'ApiFormatTestBase',
19 'ApiTestCase',
20 'MediaWikiLangTestCase',
21 'MediaWikiTestCase',
22 'PHPUnit_Framework_TestCase',
23 ) );
24 $testClassRegex = "^class .* extends ($testClassRegex)";
25 $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
26 " | xargs grep -El '$testClassRegex|function suite\('";
27
28 $results = null;
29 $exitCode = null;
30 exec($finder, $results, $exitCode);
31
32 $this->assertEquals(
33 0,
34 $exitCode,
35 'Verify find/grep command succeeds.'
36 );
37
38 $results = array_filter(
39 $results,
40 array( $this, 'filterSuites' )
41 );
42
43 $this->assertEquals(
44 array(),
45 $results,
46 'Unit test file names must end with Test.'
47 );
48 }
49
50 /**
51 * Filter to remove testUnitTestFileNamesEndWithTest false positives.
52 */
53 public function filterSuites( $filename ) {
54 return strpos( $filename, __DIR__ . '/suites/' ) !== 0;
55 }
56 }