X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiMainTest.php;h=9cb84e23bc183a3f767432d7ebdfb552e039eb70;hb=6a655e0e213337819bbe4619062b9078416724a5;hp=a6083cda8977def0a5720a2d58d750270c4da852;hpb=f96aaf6833d052d10d46af47540fff995362433e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index a6083cda89..9cb84e23bc 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -1,5 +1,6 @@ inLanguage( 'en' )->useDatabase( false )->text(); + // The specific exception doesn't matter, as long as it's namespaced. + $nsex = new MediaWiki\ShellDisabledError(); + $nstrace = wfMessage( 'api-exception-trace', + get_class( $nsex ), + $nsex->getFile(), + $nsex->getLine(), + MWExceptionHandler::getRedactedTraceAsString( $nsex ) + )->inLanguage( 'en' )->useDatabase( false )->text(); + $apiEx1 = new ApiUsageException( null, StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) ); TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar'; @@ -1017,6 +1027,13 @@ class ApiMainTest extends ApiTestCase { $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) ); $apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) ); + $badMsg = $this->getMockBuilder( ApiRawMessage::class ) + ->setConstructorArgs( [ 'An error', 'ignored' ] ) + ->setMethods( [ 'getApiCode' ] ) + ->getMock(); + $badMsg->method( 'getApiCode' )->willReturn( "bad\nvalue" ); + $apiEx2 = new ApiUsageException( null, StatusValue::newFatal( $badMsg ) ); + return [ [ $ex, @@ -1030,6 +1047,9 @@ class ApiMainTest extends ApiTestCase { [ 'code' => 'internal_api_error_InvalidArgumentException', 'text' => "[$reqId] Exception caught: Random exception", + 'data' => [ + 'errorclass' => InvalidArgumentException::class, + ], ] ], 'trace' => $trace, @@ -1049,12 +1069,36 @@ class ApiMainTest extends ApiTestCase { 'code' => 'internal_api_error_DBQueryError', 'text' => "[$reqId] Exception caught: A database query error has occurred. " . "This may indicate a bug in the software.", + 'data' => [ + 'errorclass' => DBQueryError::class, + ], ] ], 'trace' => $dbtrace, 'servedby' => wfHostname(), ] ], + [ + $nsex, + [ 'existing-error', 'internal_api_error_MediaWiki\ShellDisabledError' ], + [ + 'warnings' => [ + [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ], + ], + 'errors' => [ + [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ], + [ + 'code' => 'internal_api_error_MediaWiki\ShellDisabledError', + 'text' => "[$reqId] Exception caught: " . $nsex->getMessage(), + 'data' => [ + 'errorclass' => MediaWiki\ShellDisabledError::class, + ], + ] + ], + 'trace' => $nstrace, + 'servedby' => wfHostname(), + ] + ], [ $apiEx1, [ 'existing-error', 'sv-error1', 'sv-error2' ], @@ -1075,6 +1119,23 @@ class ApiMainTest extends ApiTestCase { 'servedby' => wfHostname(), ] ], + [ + $apiEx2, + [ 'existing-error', '' ], + [ + 'warnings' => [ + [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ], + ], + 'errors' => [ + [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ], + [ 'code' => "bad\nvalue", 'text' => 'An error' ], + ], + 'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " . + "list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> " . + "for notice of API deprecations and breaking changes.", + 'servedby' => wfHostname(), + ] + ] ]; }