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

Change subject: [WIP] Restore specific API error messages
......................................................................

[WIP] Restore specific API error messages

Change-Id: I5c26fc968fd800a9df8e65f1cf7e099fd3644648
---
M repo/tests/phpunit/includes/Api/EditEntityTest.php
M repo/tests/phpunit/includes/Api/IndependentWikibaseApiTestCase.php
M repo/tests/phpunit/includes/Api/ModifyTermTestCase.php
M repo/tests/phpunit/includes/Api/SetAliasesTest.php
M repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
5 files changed, 21 insertions(+), 14 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/Api/EditEntityTest.php 
b/repo/tests/phpunit/includes/Api/EditEntityTest.php
index 3aecc33..e20c192 100644
--- a/repo/tests/phpunit/includes/Api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/Api/EditEntityTest.php
@@ -902,6 +902,7 @@
                                'e' => [ 'exception' => [
                                        'type' => ApiUsageException::class,
                                        'code' => 'not-recognized',
+                                       'message' => '"remove" should not be a 
top-level key',
                                        'message-key' => 
'wikibase-api-not-recognized',
                                ] ],
                        ],
diff --git a/repo/tests/phpunit/includes/Api/IndependentWikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/Api/IndependentWikibaseApiTestCase.php
index 1aa9209..bd89154 100644
--- a/repo/tests/phpunit/includes/Api/IndependentWikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/Api/IndependentWikibaseApiTestCase.php
@@ -61,23 +61,33 @@
        /**
         * Do the test for exceptions from Api queries.
         * @param array $params array of params for the api query
-        * @param array $exception details of the exception to expect 
(type,code,message)
+        * @param array $exception Details of the exception to expect (type, 
code, message, message-key).
         */
        public function doTestQueryExceptions( $params, $exception ) {
                try {
                        $this->doApiRequest( $params );
-                       $this->fail( 'Failed to throw ApiUsageException' );
 
+                       $this->fail( 'Failed to throw ApiUsageException' );
                } catch ( ApiUsageException $e ) {
                        if ( array_key_exists( 'type', $exception ) ) {
                                $this->assertInstanceOf( $exception['type'], $e 
);
                        }
+
                        if ( array_key_exists( 'code', $exception ) ) {
                                $this->assertEquals( $exception['code'], 
$e->getCodeString() );
                        }
+
                        if ( array_key_exists( 'message', $exception ) ) {
                                $this->assertContains( $exception['message'], 
$e->getMessage() );
                        }
+
+                       if ( array_key_exists( 'message-key', $exception ) ) {
+                               $status = $e->getStatusValue();
+                               $this->assertTrue(
+                                       $status->hasMessage( 
$exception['message-key'] ),
+                                       'Status message key'
+                               );
+                       }
                }
        }
 
diff --git a/repo/tests/phpunit/includes/Api/ModifyTermTestCase.php 
b/repo/tests/phpunit/includes/Api/ModifyTermTestCase.php
index 4023870..bd82a75 100644
--- a/repo/tests/phpunit/includes/Api/ModifyTermTestCase.php
+++ b/repo/tests/phpunit/includes/Api/ModifyTermTestCase.php
@@ -188,6 +188,7 @@
                                'e' => array( 'exception' => array(
                                        'type' => ApiUsageException::class,
                                        'code' => 'no-such-entity-link',
+                                       'message' => 'No entity found matching 
site link'
                                ) )
                        ),
                        array( //7
@@ -195,6 +196,7 @@
                                'e' => array( 'exception' => array(
                                        'type' => ApiUsageException::class,
                                        'code' => 'param-illegal',
+                                       'message' => 'Either provide the item 
"id" or pairs'
                                ) )
                        ),
                        array( //8
@@ -202,6 +204,7 @@
                                'e' => array( 'exception' => array(
                                        'type' => ApiUsageException::class,
                                        'code' => 'param-illegal',
+                                       'message' => 'Either provide the item 
"id" or pairs'
                                ) )
                        ),
                );
diff --git a/repo/tests/phpunit/includes/Api/SetAliasesTest.php 
b/repo/tests/phpunit/includes/Api/SetAliasesTest.php
index 06707f2..7efae37 100644
--- a/repo/tests/phpunit/includes/Api/SetAliasesTest.php
+++ b/repo/tests/phpunit/includes/Api/SetAliasesTest.php
@@ -211,6 +211,7 @@
                                'e' => array( 'exception' => array(
                                        'type' => ApiUsageException::class,
                                        'code' => 'no-such-entity-link',
+                                       'message' => 'No entity found matching 
site link'
                                ) )
                        ),
                        array( //7
@@ -218,6 +219,7 @@
                                'e' => array( 'exception' => array(
                                        'type' => ApiUsageException::class,
                                        'code' => 'param-illegal',
+                                       'message' => 'Either provide the item 
"id" or pairs'
                                ) )
                        ),
                        array( //8
diff --git a/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
index aa83ce8..2b6879b 100644
--- a/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Repo\Tests\Api;
 
 use ApiTestCase;
-use Exception;
 use MediaWiki\MediaWikiServices;
 use OutOfBoundsException;
 use Revision;
@@ -167,7 +166,7 @@
         * Do the test for exceptions from Api queries.
         *
         * @param array $params Array of params for the API query.
-        * @param array $exception Details of the exception to expect (type, 
code, message).
+        * @param array $exception Details of the exception to expect (type, 
code, message, message-key).
         */
        protected function doTestQueryExceptions( array $params, array 
$exception ) {
                try {
@@ -184,9 +183,11 @@
                        if ( array_key_exists( 'type', $exception ) ) {
                                $this->assertInstanceOf( $exception['type'], $e 
);
                        }
+
                        if ( array_key_exists( 'code', $exception ) ) {
                                $this->assertEquals( $exception['code'], 
$e->getCodeString() );
                        }
+
                        if ( array_key_exists( 'message', $exception ) ) {
                                $this->assertContains( $exception['message'], 
$e->getMessage() );
                        }
@@ -197,16 +198,6 @@
                                        $status->hasMessage( 
$exception['message-key'] ),
                                        'Status message key'
                                );
-                       }
-               } catch ( Exception $e ) {
-                       if ( $e instanceof 
\PHPUnit_Framework_AssertionFailedError ) {
-                               throw $e;
-                       }
-                       if ( array_key_exists( 'type', $exception ) ) {
-                               $this->assertInstanceOf( $exception['type'], $e 
);
-                       }
-                       if ( array_key_exists( 'message', $exception ) ) {
-                               $this->assertContains( $exception['message'], 
$e->getMessage() );
                        }
                }
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c26fc968fd800a9df8e65f1cf7e099fd3644648
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