From: Adam Roses Wight Date: Sun, 28 Sep 2014 21:32:55 +0000 (-0700) Subject: Extensions may add tests by directory X-Git-Tag: 1.31.0-rc.0~13542^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=cf4654399bd3e1c109ec8f94bfa69fc44de18054;p=lhc%2Fweb%2Fwiklou.git Extensions may add tests by directory The UnitTestsList hook can now be used to add entire directories of tests, à la phpunit.xml's tag. The test suite is built by recursively scanning the directory for any files ending in "Test.php". TODO: * Update online hook documentation. * Generate and autoload a classmap for scanned directories. Bug: 70630 Change-Id: I3089372f9d7c645e16ff0984a959f982a3bc639f --- diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 2b5136eba5..03cf27708e 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -505,6 +505,9 @@ changes to languages because of Bugzilla reports. * Removed maintenance/purgeOldText.inc and the PurgeRedundantText() function it contained (superseded by Maintenance::purgeRedundantText() in 1.16). The purgeOldText.php maintenance script has been retained. +* PHPUnit tests can be found by directory discovery, by adding the directory + path from your UnitTestsList callback. Older versions of MediaWiki core will + barf at this usage. ==== Renamed classes ==== * CLDRPluralRuleConverter_Expression to CLDRPluralRuleConverterExpression diff --git a/docs/hooks.txt b/docs/hooks.txt index c60cc7618c..6fb10b12cd 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2729,8 +2729,10 @@ actions). $action: action name $article: article "acted on" -'UnitTestsList': Called when building a list of files with PHPUnit tests. -&$files: list of files +'UnitTestsList': Called when building a list of paths containing PHPUnit tests. +Since 1.24: Paths pointing to a directory will be recursively scanned for +test case files matching the suffix "Test.php". +&$paths: list of test cases and directories to search. 'UnwatchArticle': Before a watch is removed from an article. $user: user watching diff --git a/tests/phpunit/suites/ExtensionsTestSuite.php b/tests/phpunit/suites/ExtensionsTestSuite.php index 4d24d9d3a8..116065f821 100644 --- a/tests/phpunit/suites/ExtensionsTestSuite.php +++ b/tests/phpunit/suites/ExtensionsTestSuite.php @@ -8,12 +8,25 @@ class ExtensionsTestSuite extends PHPUnit_Framework_TestSuite { public function __construct() { parent::__construct(); - $files = array(); - wfRunHooks( 'UnitTestsList', array( &$files ) ); - foreach ( $files as $file ) { - $this->addTestFile( $file ); + $paths = array(); + // Extensions can return a list of files or directories + wfRunHooks( 'UnitTestsList', array( &$paths ) ); + foreach ( $paths as $path ) { + if ( is_dir( $path ) ) { + // If the path is a directory, search for test cases. + // @since 1.24 + $suffixes = array( + 'Test.php', + ); + $fileIterator = new File_Iterator_Facade(); + $matchingFiles = $fileIterator->getFilesAsArray( $path, $suffixes ); + $this->addTestFiles( $matchingFiles ); + } else { + // Add a single test case or suite class + $this->addTestFile( $path ); + } } - if ( !count( $files ) ) { + if ( !count( $paths ) ) { $this->addTest( new DummyExtensionsTest( 'testNothing' ) ); } }