3 namespace MediaWiki\Tests\Rest\Handler
;
6 use GuzzleHttp\Psr7\Uri
;
7 use MediaWiki\Rest\RequestData
;
8 use MediaWiki\Rest\ResponseFactory
;
9 use MediaWiki\Rest\Router
;
12 * @covers \MediaWiki\Rest\Handler\HelloHandler
14 class HelloHandlerTest
extends \MediaWikiUnitTestCase
{
15 public static function provideTestViaRouter() {
20 'uri' => self
::makeUri( '/user/Tim/hello' ),
24 'reasonPhrase' => 'OK',
25 'protocolVersion' => '1.1',
26 'body' => '{"message":"Hello, Tim!"}',
29 'method not allowed' => [
32 'uri' => self
::makeUri( '/user/Tim/hello' ),
36 'reasonPhrase' => 'Method Not Allowed',
37 'protocolVersion' => '1.1',
38 'body' => '{"httpCode":405,"httpReason":"Method Not Allowed"}',
44 private static function makeUri( $path ) {
45 return new Uri( "http://www.example.com/rest$path" );
48 /** @dataProvider provideTestViaRouter */
49 public function testViaRouter( $requestInfo, $responseInfo ) {
51 [ __DIR__
. '/../testRoutes.json' ],
55 new ResponseFactory() );
56 $request = new RequestData( $requestInfo );
57 $response = $router->execute( $request );
58 if ( isset( $responseInfo['statusCode'] ) ) {
59 $this->assertSame( $responseInfo['statusCode'], $response->getStatusCode() );
61 if ( isset( $responseInfo['reasonPhrase'] ) ) {
62 $this->assertSame( $responseInfo['reasonPhrase'], $response->getReasonPhrase() );
64 if ( isset( $responseInfo['protocolVersion'] ) ) {
65 $this->assertSame( $responseInfo['protocolVersion'], $response->getProtocolVersion() );
67 if ( isset( $responseInfo['body'] ) ) {
68 $this->assertSame( $responseInfo['body'], $response->getBody()->getContents() );
72 array_diff( array_keys( $responseInfo ), [
78 '$responseInfo may not contain unknown keys' );