2011-11-10 23:45:35 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* The tests here verify the structure of the code. This is for outright bugs,
|
2011-11-10 23:52:56 +00:00
|
|
|
* not just style issues.
|
2011-11-10 23:45:35 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-11-10 23:52:56 +00:00
|
|
|
class StructureTest extends MediaWikiTestCase {
|
2011-11-10 23:45:35 +00:00
|
|
|
/**
|
|
|
|
|
* Verify all files that appear to be tests have file names ending in
|
|
|
|
|
* Test. If the file names do not end in Test, they will not be run.
|
2012-12-10 00:27:39 +00:00
|
|
|
* @group medium
|
2011-11-10 23:45:35 +00:00
|
|
|
*/
|
|
|
|
|
public function testUnitTestFileNamesEndWithTest() {
|
2011-11-14 16:53:50 +00:00
|
|
|
if ( wfIsWindows() ) {
|
|
|
|
|
$this->markTestSkipped( 'This test does not work on Windows' );
|
|
|
|
|
}
|
2013-05-21 09:26:02 +00:00
|
|
|
$rootPath = escapeshellarg( __DIR__ . '/..' );
|
2011-11-10 23:45:35 +00:00
|
|
|
$testClassRegex = implode( '|', array(
|
|
|
|
|
'ApiFormatTestBase',
|
|
|
|
|
'ApiTestCase',
|
2013-03-02 00:06:46 +00:00
|
|
|
'ApiQueryTestBase',
|
|
|
|
|
'ApiQueryContinueTestBase',
|
2011-11-10 23:45:35 +00:00
|
|
|
'MediaWikiLangTestCase',
|
2014-05-26 20:16:07 +00:00
|
|
|
'MediaWikiMediaTestCase',
|
2011-11-10 23:45:35 +00:00
|
|
|
'MediaWikiTestCase',
|
2014-03-07 17:18:31 +00:00
|
|
|
'ResourceLoaderTestCase',
|
2011-11-10 23:45:35 +00:00
|
|
|
'PHPUnit_Framework_TestCase',
|
2012-04-03 10:23:03 +00:00
|
|
|
'DumpTestCase',
|
2011-11-10 23:45:35 +00:00
|
|
|
) );
|
|
|
|
|
$testClassRegex = "^class .* extends ($testClassRegex)";
|
|
|
|
|
$finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
|
|
|
|
|
" | xargs grep -El '$testClassRegex|function suite\('";
|
|
|
|
|
|
|
|
|
|
$results = null;
|
|
|
|
|
$exitCode = null;
|
2013-02-14 11:22:13 +00:00
|
|
|
exec( $finder, $results, $exitCode );
|
2011-11-10 23:45:35 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
0,
|
|
|
|
|
$exitCode,
|
|
|
|
|
'Verify find/grep command succeeds.'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$results = array_filter(
|
|
|
|
|
$results,
|
|
|
|
|
array( $this, 'filterSuites' )
|
|
|
|
|
);
|
2012-02-24 16:54:48 +00:00
|
|
|
$strip = strlen( $rootPath ) - 1;
|
2013-02-14 11:22:13 +00:00
|
|
|
foreach ( $results as $k => $v ) {
|
2012-02-24 16:54:48 +00:00
|
|
|
$results[$k] = substr( $v, $strip );
|
|
|
|
|
}
|
2011-11-10 23:45:35 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
array(),
|
|
|
|
|
$results,
|
2012-02-24 16:54:48 +00:00
|
|
|
"Unit test file in $rootPath must end with Test."
|
2011-11-10 23:45:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Filter to remove testUnitTestFileNamesEndWithTest false positives.
|
2014-08-25 16:50:35 +00:00
|
|
|
* @param string $filename
|
|
|
|
|
* @return bool
|
2011-11-10 23:45:35 +00:00
|
|
|
*/
|
|
|
|
|
public function filterSuites( $filename ) {
|
2013-05-21 09:26:02 +00:00
|
|
|
return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
|
2011-11-10 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
}
|