Daniel Kinzler has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/328151 )

Change subject: Inject ApiBase into ItemByTitleHelper for proper error reporting
......................................................................


Inject ApiBase into ItemByTitleHelper for proper error reporting

This fixes the TODO added in I7c01e3f.

Bug: T153359
Change-Id: I4ca0613c953fcf28912f7a5658e2aab4a3d51eb8
---
M repo/includes/Api/GetEntities.php
M repo/includes/Api/ItemByTitleHelper.php
M repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
3 files changed, 27 insertions(+), 2 deletions(-)

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



diff --git a/repo/includes/Api/GetEntities.php 
b/repo/includes/Api/GetEntities.php
index 02c8891..f9c7cd1 100644
--- a/repo/includes/Api/GetEntities.php
+++ b/repo/includes/Api/GetEntities.php
@@ -193,6 +193,7 @@
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
                $siteLinkStore = $wikibaseRepo->getStore()->newSiteLinkStore();
                return new ItemByTitleHelper(
+                       $this,
                        $this->resultBuilder,
                        $siteLinkStore,
                        $wikibaseRepo->getSiteLookup(),
diff --git a/repo/includes/Api/ItemByTitleHelper.php 
b/repo/includes/Api/ItemByTitleHelper.php
index 7b18296..a18219c 100644
--- a/repo/includes/Api/ItemByTitleHelper.php
+++ b/repo/includes/Api/ItemByTitleHelper.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Api;
 
+use ApiBase;
 use Profiler;
 use Site;
 use SiteLookup;
@@ -20,6 +21,11 @@
  * @author Addshore
  */
 class ItemByTitleHelper {
+
+       /**
+        * @var ApiBase
+        */
+       private $apiModule;
 
        /**
         * @var ResultBuilder
@@ -42,17 +48,20 @@
        private $stringNormalizer;
 
        /**
+        * @param ApiBase $apiModule
         * @param ResultBuilder $resultBuilder
         * @param SiteLinkLookup $siteLinkLookup
         * @param SiteLookup $siteLookup
         * @param StringNormalizer $stringNormalizer
         */
        public function __construct(
+               ApiBase $apiModule,
                ResultBuilder $resultBuilder,
                SiteLinkLookup $siteLinkLookup,
                SiteLookup $siteLookup,
                StringNormalizer $stringNormalizer
        ) {
+               $this->apiModule = $apiModule;
                $this->resultBuilder = $resultBuilder;
                $this->siteLinkLookup = $siteLinkLookup;
                $this->siteLookup = $siteLookup;
@@ -164,8 +173,7 @@
         */
        private function throwUsageException( $message, $code ) {
                Profiler::instance()->close();
-               // TODO: The API module responsible for the error should be 
passed in here.
-               throw ApiUsageException::newWithMessage( null, $message, $code 
);
+               throw ApiUsageException::newWithMessage( $this->apiModule, 
$message, $code );
        }
 
 }
diff --git a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php 
b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
index 1253fad..7a9da5d 100644
--- a/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
+++ b/repo/tests/phpunit/includes/Api/ItemByTitleHelperTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Tests\Api;
 
+use ApiBase;
 use MediaWikiSite;
 use SiteLookup;
 use Title;
@@ -23,6 +24,15 @@
  * @author Addshore
  */
 class ItemByTitleHelperTest extends \PHPUnit_Framework_TestCase {
+
+       /**
+        * @return ApiBase
+        */
+       private function getApiBaseMock() {
+               return $this->getMockBuilder( ApiBase::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+       }
 
        /**
         * @return SiteLookup
@@ -79,6 +89,7 @@
                $expectedEntityId = $expectedEntityId->getSerialization();
 
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
                        $this->getSiteLinkLookupMock( new ItemId( 'Q123' ) ),
                        $this->getSiteLookupMock(),
@@ -100,6 +111,7 @@
         */
        public function testGetEntityIdNormalized() {
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                // Two values should be added: The normalization and the 
failure to find an entity
                        $this->getResultBuilderMock( 1 ),
                        $this->getSiteLinkLookupMock( null ),
@@ -122,6 +134,7 @@
         */
        public function testGetEntityIdsNotFound() {
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                // Two result values should be added (for both titles which 
wont be found)
                        $this->getResultBuilderMock(),
                        $this->getSiteLinkLookupMock( false ),
@@ -142,6 +155,7 @@
                $this->setExpectedException( ApiUsageException::class );
 
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
                        $this->getSiteLinkLookupMock( 1 ),
                        $this->getSiteLookupMock(),
@@ -178,6 +192,7 @@
                $dummySite = new MediaWikiSite();
 
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                        $this->getResultBuilderMock( 
$expectedAddNormalizedCalls ),
                        $this->getSiteLinkLookupMock( $expectedEntityId ),
                        $this->getSiteLookupMock(),
@@ -215,6 +230,7 @@
                $this->setExpectedException( ApiUsageException::class );
 
                $itemByTitleHelper = new ItemByTitleHelper(
+                       $this->getApiBaseMock(),
                        $this->getResultBuilderMock(),
                        $this->getSiteLinkLookupMock( new ItemId( 'Q123' ) ),
                        $this->getSiteLookupMock(),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4ca0613c953fcf28912f7a5658e2aab4a3d51eb8
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to