Manual:Hooks/UnitTestsList
UnitTestsList | |
---|---|
Available from version 1.17.0 (r68673, codereview) Allows extensions to extend core's PHPUnit test suite | |
Define function: | public static function onUnitTestsList( array &$paths ) { ... }
|
Attach hook: | In extension.json:
{
"Hooks": {
"UnitTestsList": "MediaWiki\\Extension\\MyExtension\\Hooks::onUnitTestsList"
}
}
|
Called from: | File(s): ../tests/phpunit/suites/ExtensionsTestSuite.php |
Interface: | UnitTestsListHook.php |
For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:UnitTestsList extensions.
UnitTestsList allows registration of additional test suites to execute under PHPUnit. Extensions can append paths to files to the $paths
array, and since MediaWiki 1.24, can specify paths to directories, which will be scanned recursively for any test case files with the suffix "Test.php".
Registering your tests
editAs of MediaWiki 1.28 (Gerrit change 302944), you no longer need to register your tests with the
UnitTestsList
hook as long as they are in the tests/phpunit/
directory of your extension - they will automatically be registered.Let's assume our extension is named Fruits.
- Create a hook function for onUnitTestsList.
- Register the hook with UnitTestsList.
--- Fruits/Fruits.hooks.php
@@ class FruitsHooks {
public static function onUnitTestsList( &$paths ) {
$paths[] = __DIR__ . '/tests/phpunit/';
return true;
}
--- Fruits/Fruits.php
// Register hooks
$wgHooks['UnitTestsList'][] = 'FruitsHooks::onUnitTestsList';