MediaWiki REL1_31
ApiUsageExceptionTest.php
Go to the documentation of this file.
1<?php
2
7
9 $messageKey = 'some-message-key';
10 $messageParameter = 'some-parameter';
11 $statusValue = new StatusValue();
12 $statusValue->fatal( $messageKey, $messageParameter );
13
14 $apiUsageException = new ApiUsageException( null, $statusValue );
16 $gotMessage = $apiUsageException->getMessageObject();
17
18 $this->assertInstanceOf( \Message::class, $gotMessage );
19 $this->assertEquals( $messageKey, $gotMessage->getKey() );
20 $this->assertEquals( [ $messageParameter ], $gotMessage->getParams() );
21 }
22
24 $expectedMessage = new Message( 'some-message-key', [ 'some message parameter' ] );
25 $expectedCode = 'some-error-code';
26 $expectedData = [ 'some-error-data' ];
27
28 $apiUsageException = ApiUsageException::newWithMessage(
29 null,
30 $expectedMessage,
31 $expectedCode,
32 $expectedData
33 );
35 $gotMessage = $apiUsageException->getMessageObject();
36
37 $this->assertInstanceOf( \ApiMessage::class, $gotMessage );
38 $this->assertEquals( $expectedMessage->getKey(), $gotMessage->getKey() );
39 $this->assertEquals( $expectedMessage->getParams(), $gotMessage->getParams() );
40 $this->assertEquals( $expectedCode, $gotMessage->getApiCode() );
41 $this->assertEquals( $expectedData, $gotMessage->getApiData() );
42 }
43
44}
testNewWithMessage_ThenGetMessageObject_ReturnsApiMessageWithProvidedData()
Exception used to abort API execution with an error.
static newWithMessage(ApiBase $module=null, $msg, $code=null, $data=null, $httpCode=0)
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
Generic operation result class Has warning/error list, boolean status and arbitrary value.