From: Kunal Mehta Date: Thu, 4 Aug 2016 16:44:55 +0000 (-0700) Subject: Autodiscover extension unittests X-Git-Tag: 1.31.0-rc.0~6169 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=1d7221d066c01c3fa6fb3e539cebd9fe7a91550f;p=lhc%2Fweb%2Fwiklou.git Autodiscover extension unittests Instead of requiring every extension that wants to add unit tests to copy the exact same boilerplate over and over, let's just automatically discover them. We now have an extension registry, so we know exactly which extensions are loaded (this won't work for extensions not being loaded through extension.json). For each extension, we check to see if the directory "tests/phpunit/" exists, and if it does, add those unit tests. If there is a `UnitTestsList` subscriber already set, PHPUnit will automatically de-duplicate test cases so we won't be running anything twice. Change-Id: I6ec654ef2d8ee3630b121b1277b4ee21ba0b6cd4 --- diff --git a/tests/phpunit/suites/ExtensionsTestSuite.php b/tests/phpunit/suites/ExtensionsTestSuite.php index 0e23fdde82..02934fa7bd 100644 --- a/tests/phpunit/suites/ExtensionsTestSuite.php +++ b/tests/phpunit/suites/ExtensionsTestSuite.php @@ -8,10 +8,16 @@ class ExtensionsTestSuite extends PHPUnit_Framework_TestSuite { public function __construct() { parent::__construct(); + $paths = []; + // Autodiscover extension unit tests + $registry = ExtensionRegistry::getInstance(); + foreach ( $registry->getAllThings() as $info ) { + $paths[] = dirname( $info['path'] ) . '/tests/phpunit'; + } // Extensions can return a list of files or directories Hooks::run( 'UnitTestsList', [ &$paths ] ); - foreach ( $paths as $path ) { + foreach ( array_unique( $paths ) as $path ) { if ( is_dir( $path ) ) { // If the path is a directory, search for test cases. // @since 1.24 @@ -19,7 +25,7 @@ class ExtensionsTestSuite extends PHPUnit_Framework_TestSuite { $fileIterator = new File_Iterator_Facade(); $matchingFiles = $fileIterator->getFilesAsArray( $path, $suffixes ); $this->addTestFiles( $matchingFiles ); - } else { + } elseif ( file_exists( $path ) ) { // Add a single test case or suite class $this->addTestFile( $path ); }