Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / suites / ExtensionsTestSuite.php
blob02934fa7bdbef8276796e7c27bae00dad67a9bf2
1 <?php
2 /**
3 * This test suite runs unit tests registered by extensions.
4 * See https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList for details of
5 * how to register your tests.
6 */
8 class ExtensionsTestSuite extends PHPUnit_Framework_TestSuite {
9 public function __construct() {
10 parent::__construct();
12 $paths = [];
13 // Autodiscover extension unit tests
14 $registry = ExtensionRegistry::getInstance();
15 foreach ( $registry->getAllThings() as $info ) {
16 $paths[] = dirname( $info['path'] ) . '/tests/phpunit';
18 // Extensions can return a list of files or directories
19 Hooks::run( 'UnitTestsList', [ &$paths ] );
20 foreach ( array_unique( $paths ) as $path ) {
21 if ( is_dir( $path ) ) {
22 // If the path is a directory, search for test cases.
23 // @since 1.24
24 $suffixes = [ 'Test.php' ];
25 $fileIterator = new File_Iterator_Facade();
26 $matchingFiles = $fileIterator->getFilesAsArray( $path, $suffixes );
27 $this->addTestFiles( $matchingFiles );
28 } elseif ( file_exists( $path ) ) {
29 // Add a single test case or suite class
30 $this->addTestFile( $path );
33 if ( !$paths ) {
34 $this->addTest( new DummyExtensionsTest( 'testNothing' ) );
38 public static function suite() {
39 return new self;
43 /**
44 * Needed to avoid warnings like 'No tests found in class "ExtensionsTestSuite".'
45 * when no extensions with tests are used.
47 class DummyExtensionsTest extends MediaWikiTestCase {
48 public function testNothing() {
49 $this->assertTrue( true );