[MediaWiki-commits] [Gerrit] mediawiki/core[REL1_27]: Autodiscover extension unittests

2017-11-28 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
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.

Depends-On: Ia8f1581a33312521f401650e1cf7fece3c13474d
Change-Id: I6ec654ef2d8ee3630b121b1277b4ee21ba0b6cd4
(cherry picked from commit 1d7221d066c01c3fa6fb3e539cebd9fe7a91550f)
---
M tests/phpunit/suites/ExtensionsTestSuite.php
1 file changed, 8 insertions(+), 2 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



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: merged
Gerrit-Change-Id: I6ec654ef2d8ee3630b121b1277b4ee21ba0b6cd4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_27
Gerrit-Owner: Reedy 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: Reedy 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki/core[REL1_27]: Autodiscover extension unittests

2017-11-27 Thread Reedy (Code Review)
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 
Gerrit-Reviewer: Legoktm 

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