Jump to content

Manual:Hooks/UnitTestsList

From mediawiki.org
UnitTestsList
Available from version 1.17.0 (r68673, CodeReview archive)
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

[edit]
As 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.

  1. Create a hook function for onUnitTestsList.
  2. 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';

See also

[edit]
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy