3 use MediaWiki\HookContainer\HookRunner
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Registration\ExtensionRegistry
;
6 use PHPUnit\Framework\TestSuite
;
7 use SebastianBergmann\FileIterator\Facade
;
10 * This test suite runs unit tests registered by extensions.
11 * See https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList for details of
12 * how to register your tests.
15 class ExtensionsTestSuite
extends TestSuite
{
16 public function __construct() {
17 parent
::__construct();
19 if ( defined( 'MW_PHPUNIT_EXTENSIONS_TEST_PATHS' ) ) {
20 $paths = MW_PHPUNIT_EXTENSIONS_TEST_PATHS
;
23 // Autodiscover extension unit tests
24 $registry = ExtensionRegistry
::getInstance();
25 foreach ( $registry->getAllThings() as $info ) {
26 $paths[] = dirname( $info['path'] ) . '/tests/phpunit';
28 // Extensions can return a list of files or directories
29 ( new HookRunner( MediaWikiServices
::getInstance()->getHookContainer() ) )->onUnitTestsList( $paths );
32 foreach ( array_unique( $paths ) as $path ) {
33 if ( is_dir( $path ) ) {
34 // If the path is a directory, search for test cases.
36 $suffixes = [ 'Test.php' ];
37 $fileIterator = new Facade();
38 $matchingFiles = $fileIterator->getFilesAsArray( $path, $suffixes );
39 $this->addTestFiles( $matchingFiles );
40 } elseif ( is_file( $path ) ) {
41 // Add a single test case or suite class
42 $this->addTestFile( $path );
47 public static function suite() {