Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/99402
Change subject: Code style cleanup in WikibaseApiTestCase
......................................................................
Code style cleanup in WikibaseApiTestCase
Change-Id: I9fc92d6cb12a704e8941ee78576b3b1500d6735c
---
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
1 file changed, 36 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/02/99402/1
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 1d893e3..08822eb 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -3,8 +3,12 @@
namespace Wikibase\Test\Api;
use ApiTestCase;
+use Revision;
+use TestSites;
use TestUser;
+use UsageException;
use User;
+use Wikibase\EntityFactory;
use Wikibase\Settings;
/**
@@ -25,7 +29,7 @@
protected static $loginUser = null;
protected static $token = null;
- public function setUp() {
+ protected function setUp() {
global $wgUser;
parent::setUp();
@@ -45,7 +49,7 @@
$wgUser = self::$users['wbeditor']->user;
if ( !$isSetup ) {
- \TestSites::insertIntoDb();
+ TestSites::insertIntoDb();
$this->login();
@@ -60,7 +64,7 @@
/**
* Performs a login, if necessary, and returns the resulting session.
*/
- function login( $user = 'wbeditor' ) {
+ protected function login( $user = 'wbeditor' ) {
self::doLogin( $user );
self::$loginUser = self::$users[ $user ];
return self::$loginSession;
@@ -69,7 +73,7 @@
/**
* Gets an entity edit token.
*/
- function getToken( $type = 'edittoken' ) {
+ protected function getToken( $type = 'edittoken' ) {
$tokens = self::getTokenList( self::$loginUser );
return $tokens[$type];
}
@@ -77,23 +81,23 @@
/**
* Appends an edit token to a request
*/
- function doApiRequestWithToken( array $params, array $session = null,
User $user = null ) {
+ protected function doApiRequestWithToken( array $params, array $session
= null, User $user = null ) {
$params['token'] = $this->getToken();
return $this->doApiRequest( $params, $session, false, $user );
}
- function initTestEntities( $handles ){
+ protected function initTestEntities( $handles ) {
$activeHandles = EntityTestHelper::getActiveHandles();
- foreach( $activeHandles as $handle => $id ){
- if( array_key_exists( $handle, $activeHandles ) ){
+ foreach( $activeHandles as $handle => $id ) {
+ if( array_key_exists( $handle, $activeHandles ) ) {
$params = EntityTestHelper::getEntityClear(
$handle );
$params['action'] = 'wbeditentity';
$this->doApiRequestWithToken( $params );
}
}
- foreach( $handles as $handle ){
+ foreach( $handles as $handle ) {
$params = EntityTestHelper::getEntity( $handle );
$params['action'] = 'wbeditentity';
list($res,,) = $this->doApiRequestWithToken( $params );
@@ -105,7 +109,7 @@
/**
* Loads an entity from the database (via an API call).
*/
- function loadEntity( $id ) {
+ protected function loadEntity( $id ) {
list($res,,) = $this->doApiRequest(
array(
'action' => 'wbgetentities',
@@ -121,9 +125,9 @@
* @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 ){
+ public function doTestQueryExceptions( $params, $exception ) {
try{
- if( array_key_exists( 'code', $exception ) &&
$exception['code'] == 'badtoken' ){
+ if( array_key_exists( 'code', $exception ) &&
$exception['code'] == 'badtoken' ) {
if ( !self::$usetoken ) {
$this->markTestSkipped( "tokens
disabled" );
}
@@ -133,11 +137,11 @@
}
$this->fail( "Failed to throw UsageException" );
- } catch( \UsageException $e ){
- if( array_key_exists( 'type', $exception ) ){
+ } catch( UsageException $e ){
+ if( array_key_exists( 'type', $exception ) ) {
$this->assertInstanceOf( $exception['type'], $e
);
}
- if( array_key_exists( 'code', $exception ) ){
+ if( array_key_exists( 'code', $exception ) ) {
$this->assertEquals( $exception['code'],
$e->getCodeString() );
}
if( array_key_exists( 'message', $exception ) ){
@@ -266,9 +270,11 @@
if( ! ( $expectEmptyArrays === false &&
$expected['claims'] === array() ) ) {
$data = self::flattenArray( $actual['claims'],
'mainsnak', 'value', true );
$exp = self::flattenArray( $expected['claims'],
'language', 'value', true );
- for( $i = 0; $i < count( $expected['claims'] );
$i++ ){
+ $count = count( $expected['claims'] );
+
+ for( $i = 0; $i < $count; $i++ ) {
$this->assertArrayHasKey( $i,
$data['id'] );
- $this->assertGreaterThanOrEqual( 39 ,
strlen( $data['id'][$i] ) );
+ $this->assertGreaterThanOrEqual( 39,
strlen( $data['id'][$i] ) );
}
//unset stuff we dont actually want to compare
unset( $data['id'] );
@@ -296,7 +302,7 @@
* @param param string $path2 second path element (optional)
* @param param $ ...
*/
- public function assertResultHasKeyInPath( $response ){
+ public function assertResultHasKeyInPath( $response ) {
$path = func_get_args();
array_shift( $path );
@@ -315,21 +321,24 @@
* Asserts that the given API response has a valid entity type if the
result contains an entity
* @param array $response
*/
- public function assertResultHasEntityType( $response ){
-
+ public function assertResultHasEntityType( $response ) {
if ( isset( $response['entity'] ) ) {
if ( isset( $response['entity']['type'] ) ) {
- $this->assertTrue(
\Wikibase\EntityFactory::singleton()->isEntityType( $response['entity']['type']
), "Missing valid 'type' in response." );
+ $this->assertTrue(
+
EntityFactory::singleton()->isEntityType( $response['entity']['type'] ),
+ "Missing valid 'type' in response."
+ );
}
- }
- elseif ( isset( $response['entities'] ) ) {
- foreach ($response['entities'] as $entity) {
+ } elseif ( isset( $response['entities'] ) ) {
+ foreach ( $response['entities'] as $entity ) {
if ( isset( $entity['type'] ) ) {
- $this->assertTrue(
\Wikibase\EntityFactory::singleton()->isEntityType( $entity['type'] ), "Missing
valid 'type' in response." );
+ $this->assertTrue(
+
EntityFactory::singleton()->isEntityType( $entity['type'] ),
+ "Missing valid 'type' in
response."
+ );
}
}
}
-
}
/**
@@ -353,7 +362,7 @@
$regex = "!$r!";
}
- $rev = \Revision::newFromId( $revid );
+ $rev = Revision::newFromId( $revid );
$this->assertNotNull( $rev, "revision not found: $revid" );
$comment = $rev->getComment();
--
To view, visit https://gerrit.wikimedia.org/r/99402
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9fc92d6cb12a704e8941ee78576b3b1500d6735c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits