From bd2ac45fcd9ff48a94d6f77e1e0fdb7b20f6f642 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Fri, 6 Jan 2017 23:23:46 +0330 Subject: [PATCH] Better dependency injection in ListSubscribers Bug: T154574 Change-Id: Ie684d8491e76c1e4117a373d0d125efc0ba626b2 --- repo/Wikibase.php | 3 +++ repo/includes/Api/ListSubscribers.php | 7 +++---- .../phpunit/includes/Api/ListSubscribersTest.php | 16 +++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/repo/Wikibase.php b/repo/Wikibase.php index 38ddce65a5..fa6f647014 100644 --- a/repo/Wikibase.php +++ b/repo/Wikibase.php @@ -180,12 +180,15 @@ $wgAPIListModules['wbsubscribers'] = [ 'class' => Wikibase\Repo\Api\ListSubscribers::class, 'factory' => function( $mainModule, $moduleName, $modulePrefix = 'wbls' ) { + /** @var ApiQuery $mainModule */ $wikibaseRepo = \Wikibase\Repo\WikibaseRepo::getDefaultInstance(); $mediaWikiServices = \MediaWiki\MediaWikiServices::getInstance(); + $apiHelper = $wikibaseRepo->getApiHelperFactory( $mainModule->getContext() ); return new Wikibase\Repo\Api\ListSubscribers( $mainModule, $moduleName, $modulePrefix, + $apiHelper->getErrorReporter( $mainModule ), $wikibaseRepo->getEntityIdParser(), $mediaWikiServices->getSiteLookup() ); diff --git a/repo/includes/Api/ListSubscribers.php b/repo/includes/Api/ListSubscribers.php index a3fea8d147..a8fac58d89 100644 --- a/repo/includes/Api/ListSubscribers.php +++ b/repo/includes/Api/ListSubscribers.php @@ -11,7 +11,6 @@ use stdClass; use Wikibase\DataModel\Entity\EntityIdParser; use Wikibase\DataModel\Entity\EntityIdParsingException; -use Wikibase\Repo\WikibaseRepo; /** * API module for getting wikis subscribed to changes to given entities. @@ -42,6 +41,7 @@ class ListSubscribers extends ApiQueryBase { * @param ApiQuery $mainModule * @param string $moduleName * @param string $modulePrefix + * @param ApiErrorReporter $errorReporter * @param EntityIdParser $idParser * @param SiteLookup $siteLookup * @@ -51,14 +51,13 @@ public function __construct( ApiQuery $mainModule, $moduleName, $modulePrefix, + ApiErrorReporter $errorReporter, EntityIdParser $idParser, SiteLookup $siteLookup ) { parent::__construct( $mainModule, $moduleName, $modulePrefix ); - $wikibaseRepo = WikibaseRepo::getDefaultInstance(); - $this->errorReporter = $wikibaseRepo->getApiHelperFactory( $this->getContext() ) - ->getErrorReporter( $this ); + $this->errorReporter = $errorReporter; $this->idParser = $idParser; $this->siteLookup = $siteLookup; } diff --git a/repo/tests/phpunit/includes/Api/ListSubscribersTest.php b/repo/tests/phpunit/includes/Api/ListSubscribersTest.php index 12302af55f..1c009efe3a 100644 --- a/repo/tests/phpunit/includes/Api/ListSubscribersTest.php +++ b/repo/tests/phpunit/includes/Api/ListSubscribersTest.php @@ -5,9 +5,10 @@ use ApiMain; use ApiQuery; use FauxRequest; -use MediaWiki\MediaWikiServices; +use HashSiteStore; use MediaWikiLangTestCase; use RequestContext; +use Wikibase\DataModel\Entity\BasicEntityIdParser; use Wikibase\Repo\Api\ListSubscribers; use Wikibase\Repo\WikibaseRepo; @@ -86,13 +87,18 @@ private function getQueryModule( array $params ) { */ private function callApiModule( array $params ) { $wikibaseRepo = WikibaseRepo::getDefaultInstance(); - $mediaWikiServices = MediaWikiServices::getInstance(); + $apiMain = $this->getQueryModule( $params ); + $errorReporter = $wikibaseRepo->getApiHelperFactory( $apiMain->getContext() ) + ->getErrorReporter( $apiMain ); + $idParser = new BasicEntityIdParser(); + $siteLokup = new HashSiteStore(); $module = new ListSubscribers( - $this->getQueryModule( $params ), + $apiMain, 'subscribers', 'wbls', - $wikibaseRepo->getEntityIdParser(), - $mediaWikiServices->getSiteLookup() + $errorReporter, + $idParser, + $siteLokup ); $module->execute();