X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiMainTest.php;h=83eba54bf888ac58b659885a3c762287ae071640;hp=3e6ceb7a6e4cd23b4512ab5b3aaa7b56b5f58d2f;hb=faf7cc4a09848c538320bd2b9067b1a77c0a0183;hpb=143f36732f4af09ad1696a5f9a18122047004590 diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index 3e6ceb7a6e..83eba54bf8 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -45,9 +45,11 @@ class ApiMainTest extends ApiTestCase { * @param string|bool $error False if no error expected */ public function testAssert( $registered, $rights, $assert, $error ) { - $user = new User(); if ( $registered ) { - $user->setId( 1 ); + $user = $this->getMutableTestUser()->getUser(); + $user->load(); // load before setting mRights + } else { + $user = new User(); } $user->mRights = $rights; try { @@ -57,7 +59,8 @@ class ApiMainTest extends ApiTestCase { ], null, null, $user ); $this->assertFalse( $error ); // That no error was expected } catch ( ApiUsageException $e ) { - $this->assertTrue( self::apiExceptionHasCode( $e, $error ) ); + $this->assertTrue( self::apiExceptionHasCode( $e, $error ), + "Error '{$e->getMessage()}' matched expected '$error'" ); } } @@ -123,7 +126,7 @@ class ApiMainTest extends ApiTestCase { $priv = TestingAccessWrapper::newFromObject( $api ); $priv->mInternalMode = false; - $module = $this->getMockBuilder( 'ApiBase' ) + $module = $this->getMockBuilder( ApiBase::class ) ->setConstructorArgs( [ $api, 'mock' ] ) ->setMethods( [ 'getConditionalRequestData' ] ) ->getMockForAbstractClass(); @@ -220,7 +223,7 @@ class ApiMainTest extends ApiTestCase { $priv = TestingAccessWrapper::newFromObject( $api ); $priv->mInternalMode = false; - $module = $this->getMockBuilder( 'ApiBase' ) + $module = $this->getMockBuilder( ApiBase::class ) ->setConstructorArgs( [ $api, 'mock' ] ) ->setMethods( [ 'getConditionalRequestData' ] ) ->getMockForAbstractClass(); @@ -488,7 +491,7 @@ class ApiMainTest extends ApiTestCase { )->inLanguage( 'en' )->useDatabase( false )->text(); $dbex = new DBQueryError( - $this->createMock( 'IDatabase' ), + $this->createMock( \Wikimedia\Rdbms\IDatabase::class ), 'error', 1234, 'SELECT 1', __METHOD__ ); $dbtrace = wfMessage( 'api-exception-trace', get_class( $dbex ), @@ -497,6 +500,10 @@ class ApiMainTest extends ApiTestCase { MWExceptionHandler::getRedactedTraceAsString( $dbex ) )->inLanguage( 'en' )->useDatabase( false )->text(); + MediaWiki\suppressWarnings(); + $usageEx = new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ); + MediaWiki\restoreWarnings(); + $apiEx1 = new ApiUsageException( null, StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) ); TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar'; @@ -542,7 +549,7 @@ class ApiMainTest extends ApiTestCase { ] ], [ - new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ), + $usageEx, [ 'existing-error', 'ue' ], [ 'warnings' => [