Reedy has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393704 )

Change subject: Autodiscover extension unittests
......................................................................

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
(cherry picked from commit 1d7221d066c01c3fa6fb3e539cebd9fe7a91550f)
---
M tests/phpunit/suites/ExtensionsTestSuite.php
1 file changed, 8 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/04/393704/1

diff --git a/tests/phpunit/suites/ExtensionsTestSuite.php 
b/tests/phpunit/suites/ExtensionsTestSuite.php
index 0e23fdd..02934fa 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 @@
                                $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 );
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/393704
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ec654ef2d8ee3630b121b1277b4ee21ba0b6cd4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_27
Gerrit-Owner: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to