X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fstructure%2FStructureTest.php;h=97bed4c7a8cddc7832dc8918f729eaa7f562271d;hp=4df791ecd89725f683ab337cad0afbd69fc50bb3;hb=2f5d88819799f077f4d3a3288dad104141692f20;hpb=0c2687f44eb0e8c7f480b7303f89056682ba0bfb diff --git a/tests/phpunit/structure/StructureTest.php b/tests/phpunit/structure/StructureTest.php index 4df791ecd8..97bed4c7a8 100644 --- a/tests/phpunit/structure/StructureTest.php +++ b/tests/phpunit/structure/StructureTest.php @@ -9,12 +9,12 @@ 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 + * @coversNothing */ public function testUnitTestFileNamesEndWithTest() { - if ( wfIsWindows() ) { - $this->markTestSkipped( 'This test does not work on Windows' ); - } - $rootPath = escapeshellarg( __DIR__ . '/..' ); + // realpath() also normalizes directory separator on windows for prefix compares + $rootPath = realpath( __DIR__ . '/..' ); + $suitesPath = realpath( __DIR__ . '/../suites/' ); $testClassRegex = implode( '|', [ 'ApiFormatTestBase', 'ApiTestCase', @@ -28,26 +28,26 @@ class StructureTest extends MediaWikiTestCase { '\\?PHPUnit\\Framework\\TestCase', 'TestCase', // \PHPUnit\Framework\TestCase with appropriate use statement 'DumpTestCase', + 'SpecialPageTestBase', ] ); - $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 ); + $testClassRegex = "/^class .* extends ($testClassRegex)/m"; - $this->assertEquals( - 0, - $exitCode, - 'Verify find/grep command succeeds.' - ); + $results = $this->recurseFiles( $rootPath ); $results = array_filter( $results, - [ $this, 'filterSuites' ] + function ( $filename ) use ( $testClassRegex, $suitesPath ) { + // Remove testUnitTestFileNamesEndWithTest false positives + if ( strpos( $filename, $suitesPath ) === 0 + || substr( $filename, -8 ) === 'Test.php' + ) { + return false; + } + $contents = file_get_contents( $filename ); + return preg_match( $testClassRegex, $contents ); + } ); - $strip = strlen( $rootPath ) - 1; + $strip = strlen( $rootPath ) + 1; foreach ( $results as $k => $v ) { $results[$k] = substr( $v, $strip ); } @@ -58,12 +58,7 @@ class StructureTest extends MediaWikiTestCase { ); } - /** - * Filter to remove testUnitTestFileNamesEndWithTest false positives. - * @param string $filename - * @return bool - */ - public function filterSuites( $filename ) { - return strpos( $filename, __DIR__ . '/../suites/' ) !== 0; + private function recurseFiles( $dir ) { + return ( new File_Iterator_Facade() )->getFilesAsArray( $dir, [ '.php' ] ); } }