Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/286253
Change subject: registration: Add new "UnitTests" option ...................................................................... registration: Add new "UnitTests" option It does similar things like the UnitTestFiles hook and makes sure, that unit test files (or directories) are added to the unit test file list without the need of running the hook by the extension developer itself. Bug: T126093 Change-Id: Id190f0372afcec6dab51ce99a0dd5192949d3b24 --- M docs/extension.schema.json M includes/registration/ExtensionProcessor.php M tests/phpunit/suites/ExtensionsTestSuite.php 3 files changed, 26 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/53/286253/1 diff --git a/docs/extension.schema.json b/docs/extension.schema.json old mode 100644 new mode 100755 index 3c2c057..b98e95e --- a/docs/extension.schema.json +++ b/docs/extension.schema.json @@ -799,6 +799,10 @@ "load_composer_autoloader": { "type": "boolean", "description": "Load the composer autoloader for this extension, if one is present" + }, + "UnitTests": { + "type": "array", + "description": "List of files or directories with phpunit test cases (you can use this instead of the UnitTestFiles hook)." } } } diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php old mode 100644 new mode 100755 index f977124..5ec153c --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -148,6 +148,14 @@ protected $attributes = []; /** + * Holds an array of files to add as unit tests using the UnitTestFiles + * hook. + * + * @var array + */ + public static $unitTestsPaths = []; + + /** * @param string $path * @param array $info * @param int $version manifest_version for info @@ -162,6 +170,7 @@ $this->extractNamespaces( $info ); $this->extractResourceLoaderModules( $dir, $info ); $this->extractParserTestFiles( $dir, $info ); + $this->extractUnitTestFiles( $dir, $info ); if ( isset( $info['callback'] ) ) { $this->callbacks[] = $info['callback']; } @@ -367,6 +376,18 @@ } } + protected function extractUnitTestFiles( $dir, array $info ) { + if ( isset( $info['UnitTests'] ) ) { + $unitTests = $info['UnitTests']; + if ( !is_array( $unitTests ) ) { + $unitTests = [ $unitTests ]; + } + self::$unitTestsPaths += array_map( function ( $path ) use ( $dir ) { + return "$dir/$path"; + }, $unitTests ); + } + } + /** * @param string $path * @param string $name diff --git a/tests/phpunit/suites/ExtensionsTestSuite.php b/tests/phpunit/suites/ExtensionsTestSuite.php old mode 100644 new mode 100755 index 0e23fdd..9253c35 --- a/tests/phpunit/suites/ExtensionsTestSuite.php +++ b/tests/phpunit/suites/ExtensionsTestSuite.php @@ -11,6 +11,7 @@ $paths = []; // Extensions can return a list of files or directories Hooks::run( 'UnitTestsList', [ &$paths ] ); + $paths = array_merge( $paths, ExtensionProcessor::$unitTestsPaths ); foreach ( $paths as $path ) { if ( is_dir( $path ) ) { // If the path is a directory, search for test cases. -- To view, visit https://gerrit.wikimedia.org/r/286253 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id190f0372afcec6dab51ce99a0dd5192949d3b24 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits