X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fstructure%2FStructureTest.php;h=412ee991f9eb89d0700317f53e354651b9329132;hb=9c7f6734c397a954b8eaa5ec73876f2b4bf92afb;hp=82302b175860e0d2b51b6ecd883f7a037cce6057;hpb=284bc0b5eb1c0e47d7100d5604ab4d5180dcd8d5;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/structure/StructureTest.php b/tests/phpunit/structure/StructureTest.php index 82302b1758..412ee991f9 100644 --- a/tests/phpunit/structure/StructureTest.php +++ b/tests/phpunit/structure/StructureTest.php @@ -9,13 +9,11 @@ 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', @@ -29,26 +27,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 ); } @@ -59,12 +57,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' ] ); } }