wiki.techinc.nl/tests/phpunit/structure/StructureTest.php
Antoine Musso f87320bdac tests: group structures tests in their own directory
The phpunit root directory has two test file:

 AutoLoaderTest.php
 StructureTest.php

The later was registered in phpunit under the `structure` test suite
while the former was not registered and hence never run (bug 47750).

This patch moves both files under the `structure` subdirectory and
change the suite to look in that directory.  That will avoid us having
to manually maintain a list of test files.

Updated the __DIR__ in StructureTest.php.

Change-Id: I419c9157f32bdf7e1ff26a42f4bb3f3922b7be37
2013-05-21 12:33:42 +02:00

63 lines
1.6 KiB
PHP

<?php
/**
* The tests here verify the structure of the code. This is for outright bugs,
* not just style issues.
*/
class StructureTest extends MediaWikiTestCase {
/**
* 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.
* @group medium
*/
public function testUnitTestFileNamesEndWithTest() {
if ( wfIsWindows() ) {
$this->markTestSkipped( 'This test does not work on Windows' );
}
$rootPath = escapeshellarg( __DIR__ . '/..' );
$testClassRegex = implode( '|', array(
'ApiFormatTestBase',
'ApiTestCase',
'ApiQueryTestBase',
'ApiQueryContinueTestBase',
'MediaWikiLangTestCase',
'MediaWikiTestCase',
'PHPUnit_Framework_TestCase',
'DumpTestCase',
) );
$testClassRegex = "^class .* extends ($testClassRegex)";
$finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" .
" | xargs grep -El '$testClassRegex|function suite\('";
$results = null;
$exitCode = null;
exec( $finder, $results, $exitCode );
$this->assertEquals(
0,
$exitCode,
'Verify find/grep command succeeds.'
);
$results = array_filter(
$results,
array( $this, 'filterSuites' )
);
$strip = strlen( $rootPath ) - 1;
foreach ( $results as $k => $v ) {
$results[$k] = substr( $v, $strip );
}
$this->assertEquals(
array(),
$results,
"Unit test file in $rootPath must end with Test."
);
}
/**
* Filter to remove testUnitTestFileNamesEndWithTest false positives.
*/
public function filterSuites( $filename ) {
return strpos( $filename, __DIR__ . '/../suites/' ) !== 0;
}
}