Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78522


Change subject: Move queryExceptionTest to ApiTestBase
......................................................................

Move queryExceptionTest to ApiTestBase

This makes sense as all api queries can throw
these exceptions and the format of the check
is always the same
Change-Id: I476bfed19f8aadb48ff8ca2de192bc2d5410a21d
---
M repo/tests/phpunit/includes/api/LangAttributeTestCase.php
M repo/tests/phpunit/includes/api/LinkTitlesTest.php
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
3 files changed, 33 insertions(+), 56 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/api/LangAttributeTestCase.php 
b/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
index 1f0e849..b45f8b9 100644
--- a/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
+++ b/repo/tests/phpunit/includes/api/LangAttributeTestCase.php
@@ -194,34 +194,7 @@
                if( !array_key_exists( 'id', $params )  && !array_key_exists( 
'site', $params ) && !array_key_exists( 'title', $params ) ){
                        $params['id'] = EntityTestHelper::getId( 'Empty' );
                }
-
-               // -- catch and check expected exceptions ---------------------
-               try{
-                       if( $expected['exception']['code'] == 'badtoken' ){
-                               if ( !self::$usetoken ) {
-                                       $this->markTestSkipped( "tokens 
disabled" );
-                               }
-                               $this->doApiRequest( $params );
-                       } else {
-                               $this->doApiRequestWithToken( $params );
-                       }
-                       $this->fail( "Failed to throw exception, 
{$expected['exception']['type']} " );
-
-               } catch( \Exception $exception ){
-
-                       /** @var $exception \UsageException */ // trick IDEs 
into not showing errors
-                       if( array_key_exists( 'type', $expected['exception'] ) 
){
-                               $this->assertInstanceOf( 
$expected['exception']['type'], $exception );
-                       }
-
-                       if( array_key_exists( 'code', $expected['exception'] ) 
){
-                               $this->assertEquals( 
$expected['exception']['code'], $exception->getCodeString() );
-                       }
-
-                       if( array_key_exists( 'message', $expected['exception'] 
) ){
-                               $this->assertContains( 
$expected['exception']['message'], $exception->getMessage() );
-                       }
-               }
+               $this->doTestQueryExceptions( $params, $expected['exception'] );
        }
 
 }
diff --git a/repo/tests/phpunit/includes/api/LinkTitlesTest.php 
b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
index e7aae2c..bd3404e 100644
--- a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
+++ b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
@@ -147,34 +147,7 @@
        public function testLinkTitlesExceptions( $params, $expected ){
                // -- set any defaults ------------------------------------
                $params['action'] = 'wblinktitles';
-
-               // -- catch and check expected exceptions ---------------------
-               try{
-                       if( $expected['exception']['code'] == 'badtoken' ){
-                               if ( !self::$usetoken ) {
-                                       $this->markTestSkipped( "tokens 
disabled" );
-                               }
-                               $this->doApiRequest( $params );
-                       } else {
-                               $this->doApiRequestWithToken( $params );
-                       }
-                       $this->fail( "Failed to throw exception, 
{$expected['exception']['type']} " );
-
-               } catch( \Exception $exception ){
-
-                       /** @var $exception \UsageException */ // trick IDEs 
into not showing errors
-                       if( array_key_exists( 'type', $expected['exception'] ) 
){
-                               $this->assertInstanceOf( 
$expected['exception']['type'], $exception );
-                       }
-
-                       if( array_key_exists( 'code', $expected['exception'] ) 
){
-                               $this->assertEquals( 
$expected['exception']['code'], $exception->getCodeString() );
-                       }
-
-                       if( array_key_exists( 'message', $expected['exception'] 
) ){
-                               $this->assertContains( 
$expected['exception']['message'], $exception->getMessage() );
-                       }
-               }
+               $this->doTestQueryExceptions( $params, $expected['exception'] );
        }
 
 }
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 76bf209..1f652d6 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -152,6 +152,37 @@
        }
 
        /**
+        * Do the test for exceptions from Api queries.
+        * @param $params array of params for the api query
+        * @param $exception array details of the exception to expect 
(type,code,message)
+        */
+       public function doTestQueryExceptions( $params, $exception ){
+               try{
+                       if( array_key_exists( 'code', $exception ) && 
$exception['code'] == 'badtoken' ){
+                               if ( !self::$usetoken ) {
+                                       $this->markTestSkipped( "tokens 
disabled" );
+                               }
+                               $this->doApiRequest( $params );
+                       } else {
+                               $this->doApiRequestWithToken( $params );
+                       }
+                       $this->fail( "Failed to throw exception, 
{$exception['type']} " );
+
+               } catch( \Exception $e ){
+                       /** @var $e \UsageException */ // trick IDEs into not 
showing errors
+                       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() );
+                       }
+               }
+       }
+
+       /**
         * Utility function for converting an array from "deep" (indexed) to 
"flat" (keyed) structure.
         * Arrays that already use a flat structure are left unchanged.
         *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I476bfed19f8aadb48ff8ca2de192bc2d5410a21d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to