From: Antoine Musso Date: Tue, 21 May 2013 09:26:02 +0000 (+0200) Subject: tests: group structures tests in their own directory X-Git-Tag: 1.31.0-rc.0~19541^2 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=f87320bdac04cc8a45a7d1898973ec9079e0adfb;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/tests/phpunit/AutoLoaderTest.php b/tests/phpunit/AutoLoaderTest.php deleted file mode 100644 index e49ea6d978..0000000000 --- a/tests/phpunit/AutoLoaderTest.php +++ /dev/null @@ -1,50 +0,0 @@ -assertEquals( - $results['expected'], - $results['actual'] - ); - } - - protected static function checkAutoLoadConf() { - global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP; - $supportsParsekit = function_exists( 'parsekit_compile_file' ); - - // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php - $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses; - $actual = array(); - - $files = array_unique( $expected ); - - foreach ( $files as $file ) { - // Only prefix $IP if it doesn't have it already. - // Generally local classes don't have it, and those from extensions and test suites do. - if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) { - $filePath = "$IP/$file"; - } else { - $filePath = $file; - } - if ( $supportsParsekit ) { - $parseInfo = parsekit_compile_file( "$filePath" ); - $classes = array_keys( $parseInfo['class_table'] ); - } else { - $contents = file_get_contents( "$filePath" ); - $m = array(); - preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER ); - $classes = $m[1]; - } - foreach ( $classes as $class ) { - $actual[$class] = $file; - } - } - - return array( - 'expected' => $expected, - 'actual' => $actual, - ); - } -} diff --git a/tests/phpunit/StructureTest.php b/tests/phpunit/StructureTest.php deleted file mode 100644 index a9420981ec..0000000000 --- a/tests/phpunit/StructureTest.php +++ /dev/null @@ -1,63 +0,0 @@ -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; - } -} diff --git a/tests/phpunit/structure/AutoLoaderTest.php b/tests/phpunit/structure/AutoLoaderTest.php new file mode 100644 index 0000000000..e49ea6d978 --- /dev/null +++ b/tests/phpunit/structure/AutoLoaderTest.php @@ -0,0 +1,50 @@ +assertEquals( + $results['expected'], + $results['actual'] + ); + } + + protected static function checkAutoLoadConf() { + global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP; + $supportsParsekit = function_exists( 'parsekit_compile_file' ); + + // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php + $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses; + $actual = array(); + + $files = array_unique( $expected ); + + foreach ( $files as $file ) { + // Only prefix $IP if it doesn't have it already. + // Generally local classes don't have it, and those from extensions and test suites do. + if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) { + $filePath = "$IP/$file"; + } else { + $filePath = $file; + } + if ( $supportsParsekit ) { + $parseInfo = parsekit_compile_file( "$filePath" ); + $classes = array_keys( $parseInfo['class_table'] ); + } else { + $contents = file_get_contents( "$filePath" ); + $m = array(); + preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER ); + $classes = $m[1]; + } + foreach ( $classes as $class ) { + $actual[$class] = $file; + } + } + + return array( + 'expected' => $expected, + 'actual' => $actual, + ); + } +} diff --git a/tests/phpunit/structure/StructureTest.php b/tests/phpunit/structure/StructureTest.php new file mode 100644 index 0000000000..df00d4df22 --- /dev/null +++ b/tests/phpunit/structure/StructureTest.php @@ -0,0 +1,63 @@ +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; + } +} diff --git a/tests/phpunit/suite.xml b/tests/phpunit/suite.xml index 56f6447779..844c853510 100644 --- a/tests/phpunit/suite.xml +++ b/tests/phpunit/suite.xml @@ -29,7 +29,7 @@ maintenance - StructureTest.php + structure suites/UploadFromUrlTestSuite.php