Merge "Fix and make some types in PHPDoc and JSDoc tags more specific"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiMainTest.php
index 922f7f1..ad334e9 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
  * @group API
  * @group Database
@@ -43,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 {
@@ -55,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'" );
                }
        }
 
@@ -472,7 +477,7 @@ class ApiMainTest extends ApiTestCase {
                );
        }
 
-       // Not static so $this->getMock() can be used
+       // Not static so $this can be used
        public function provideExceptionErrors() {
                $reqId = WebRequest::getRequestId();
                $doclink = wfExpandUrl( wfScript( 'api' ) );
@@ -485,7 +490,9 @@ class ApiMainTest extends ApiTestCase {
                        MWExceptionHandler::getRedactedTraceAsString( $ex )
                )->inLanguage( 'en' )->useDatabase( false )->text();
 
-               $dbex = new DBQueryError( $this->getMock( 'IDatabase' ), 'error', 1234, 'SELECT 1', __METHOD__ );
+               $dbex = new DBQueryError(
+                       $this->createMock( 'IDatabase' ),
+                       'error', 1234, 'SELECT 1', __METHOD__ );
                $dbtrace = wfMessage( 'api-exception-trace',
                        get_class( $dbex ),
                        $dbex->getFile(),
@@ -493,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';
@@ -538,7 +549,7 @@ class ApiMainTest extends ApiTestCase {
                                ]
                        ],
                        [
-                               new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ),
+                               $usageEx,
                                [ 'existing-error', 'ue' ],
                                [
                                        'warnings' => [