Debian Codegraph @

tests/phpunit/suites/ExtensionsTestSuite.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\HookContainer\HookRunner;
4 use MediaWiki\MediaWikiServices;
5 use MediaWiki\Registration\ExtensionRegistry;
6 use PHPUnit\Framework\TestSuite;
7 use SebastianBergmann\FileIterator\Facade;
8
9 /**
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.
13 */
14
15 class ExtensionsTestSuite extends TestSuite {
16 public function __construct() {
17 parent::__construct();
18
19 if ( defined( 'MW_PHPUNIT_EXTENSIONS_TEST_PATHS' ) ) {
20 $paths = MW_PHPUNIT_EXTENSIONS_TEST_PATHS;
21 } else {
22 $paths = [];
23 // Autodiscover extension unit tests
24 $registry = ExtensionRegistry::getInstance();
25 foreach ( $registry->getAllThings() as $info ) {
26 $paths[] = dirname( $info['path'] ) . '/tests/phpunit';
27 }
28 // Extensions can return a list of files or directories
29 ( new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onUnitTestsList( $paths );
30 }
31
32 foreach ( array_unique( $paths ) as $path ) {
33 if ( is_dir( $path ) ) {
34 // If the path is a directory, search for test cases.
35 // @since 1.24
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 );
43 }
44 }
45 }
46
47 public static function suite() {
48 return new self;
49 }
50 }