From 42312dd466fa1319d49fd16b5ae1d8366a14650d Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 11 Sep 2018 18:16:26 +0100 Subject: [PATCH] tests: Throw when tests run that "need a db" but miss Database group Depends-On: I5cfea2dc4e56ed4639126e35c0f8aa370852f056 Depends-On: Ic472eb073290793c432812ae8b47ab2b41e74a26 Change-Id: I4cdc8130032340726c5d18d795cd2d6b6b58b307 --- tests/phpunit/MediaWikiTestCase.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 0778ab906e..de01b478b3 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -387,6 +387,12 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { } $this->overrideMwServices(); + if ( $this->needsDB() && !$this->isTestInDatabaseGroup() ) { + throw new Exception( + get_class( $this ) . ' apparently needsDB but is not in the Database group' + ); + } + $needsResetDB = false; if ( !self::$dbSetup || $this->needsDB() ) { // set up a DB connection for this test to use @@ -1062,18 +1068,18 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { */ public function needsDB() { // If the test says it uses database tables, it needs the database - if ( $this->tablesUsed ) { - return true; - } + return $this->tablesUsed || $this->isTestInDatabaseGroup(); + } + /** + * @return bool + * @since 1.32 + */ + protected function isTestInDatabaseGroup() { // If the test class says it belongs to the Database group, it needs the database. // NOTE: This ONLY checks for the group in the class level doc comment. $rc = new ReflectionClass( $this ); - if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) { - return true; - } - - return false; + return (bool)preg_match( '/@group +Database/im', $rc->getDocComment() ); } /** -- 2.20.1