Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/360872 )

Change subject: Minor refactorings and cleanups in ApiErrorReporter and tests
......................................................................

Minor refactorings and cleanups in ApiErrorReporter and tests

This is trivial refactoring split from Ib5b1eae to make it easier to
review. If this patch here is merged fast, I will rebase the bigger one.

Bug: T153359
Change-Id: I37c8b0beaa31e300eb3ca073718bb72dcdeb0bf1
---
M repo/includes/Api/ApiErrorReporter.php
M repo/tests/phpunit/includes/Api/ApiErrorReporterTest.php
2 files changed, 13 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/72/360872/1

diff --git a/repo/includes/Api/ApiErrorReporter.php 
b/repo/includes/Api/ApiErrorReporter.php
index 6249bdd..b3cb17a 100644
--- a/repo/includes/Api/ApiErrorReporter.php
+++ b/repo/includes/Api/ApiErrorReporter.php
@@ -117,7 +117,7 @@
                //XXX: when to prefer $statusCode over $errorCode?
                list( , $description ) = $this->apiModule->getErrorFromStatus( 
$status );
 
-               $this->throwUsageException( $description, $errorCode, 
$httpRespCode, $extradata );
+               $this->throwUsageException( $description, $errorCode, 
$extradata, $httpRespCode );
 
                throw new LogicException( 'ApiUsageException not thrown' );
        }
@@ -170,15 +170,10 @@
         * @throws LogicException
         */
        public function dieMessage( $errorCode /*...*/ ) {
-               $messageName = "wikibase-api-$errorCode";
+               $messageKey = "wikibase-api-$errorCode";
                $params = func_get_args();
                array_shift( $params );
-               $message = wfMessage( $messageName, $params );
-
-               if ( !$message->exists() ) {
-                       // TODO: log warning
-                       // TODO: replace with generic message
-               }
+               $message = wfMessage( $messageKey, $params );
 
                $this->dieMessageObject( $message, $errorCode );
 
@@ -207,7 +202,7 @@
 
                $this->addMessageToResult( $message, $extradata );
 
-               $this->throwUsageException( $description, $errorCode, 
$httpRespCode, $extradata );
+               $this->throwUsageException( $description, $errorCode, 
$extradata, $httpRespCode );
 
                throw new LogicException( 'ApiUsageException not thrown' );
        }
@@ -248,7 +243,7 @@
                        }
                }
 
-               $this->throwUsageException( $description, $errorCode, 
$httpRespCode, $extradata );
+               $this->throwUsageException( $description, $errorCode, 
$extradata, $httpRespCode );
 
                throw new LogicException( 'ApiUsageException not thrown' );
        }
@@ -260,17 +255,17 @@
         *
         * @param string $description
         * @param string $errorCode
-        * @param int $httpRespCode
-        * @param null|array $extradata
+        * @param array|null $data See ApiMessage::create()
+        * @param int $httpCode HTTP error code to use
         *
         * @throws ApiUsageException
         * @throws LogicException
         */
-       private function throwUsageException( $description, $errorCode, 
$httpRespCode = 0, $extradata = null ) {
+       private function throwUsageException( $description, $errorCode, array 
$data = null, $httpCode = 0 ) {
                $stats = 
MediaWikiServices::getInstance()->getStatsdDataFactory();
                $stats->increment( 'wikibase.repo.api.errors.total' );
 
-               $this->apiModule->getMain()->dieUsage( $description, 
$errorCode, $httpRespCode, $extradata );
+               $this->apiModule->getMain()->dieUsage( $description, 
$errorCode, $httpCode, $data );
 
                throw new LogicException( 'ApiUsageException not thrown' );
        }
diff --git a/repo/tests/phpunit/includes/Api/ApiErrorReporterTest.php 
b/repo/tests/phpunit/includes/Api/ApiErrorReporterTest.php
index 3b0ea42..4a8f788 100644
--- a/repo/tests/phpunit/includes/Api/ApiErrorReporterTest.php
+++ b/repo/tests/phpunit/includes/Api/ApiErrorReporterTest.php
@@ -39,15 +39,15 @@
                $this->assertArrayHasKey( 'info', $messageArray );
 
                if ( $info !== null ) {
-                       $this->assertRegExp( $info, $messageArray['info'] );
+                       $this->assertRegExp( $info, $messageArray['info'], 
'error info message' );
                }
 
                if ( $code !== null ) {
-                       $this->assertEquals( $code, $messageArray['code'] );
+                       $this->assertSame( $code, $messageArray['code'], 'error 
code' );
                }
 
                if ( $httpStatusCode ) {
-                       $this->assertEquals( $httpStatusCode, $ex->getCode() );
+                       $this->assertSame( $httpStatusCode, $ex->getCode(), 
'HTTP status code' );
                }
 
                foreach ( $expectedDataFields as $path => $value ) {
@@ -68,7 +68,7 @@
                        $this->assertInternalType( 'string', $data, $name );
                        $this->assertRegExp( $expected, $data, $name );
                } else {
-                       $this->assertEquals( $expected, $data, $name );
+                       $this->assertSame( $expected, $data, $name );
                }
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37c8b0beaa31e300eb3ca073718bb72dcdeb0bf1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to