lockmanager: disable internal QuorumLockManager methods that should never be reached
[lhc/web/wiklou.git] / tests / phpunit / includes / Rest / Handler / HelloHandlerTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Rest\Handler;
4
5 use EmptyBagOStuff;
6 use GuzzleHttp\Psr7\Uri;
7 use MediaWiki\Rest\RequestData;
8 use MediaWiki\Rest\ResponseFactory;
9 use MediaWiki\Rest\Router;
10 use MediaWikiTestCase;
11
12 /**
13 * @covers \MediaWiki\Rest\Handler\HelloHandler
14 */
15 class HelloHandlerTest extends MediaWikiTestCase {
16 public static function provideTestViaRouter() {
17 return [
18 'normal' => [
19 [
20 'method' => 'GET',
21 'uri' => self::makeUri( '/user/Tim/hello' ),
22 ],
23 [
24 'statusCode' => 200,
25 'reasonPhrase' => 'OK',
26 'protocolVersion' => '1.1',
27 'body' => '{"message":"Hello, Tim!"}',
28 ],
29 ],
30 'method not allowed' => [
31 [
32 'method' => 'POST',
33 'uri' => self::makeUri( '/user/Tim/hello' ),
34 ],
35 [
36 'statusCode' => 405,
37 'reasonPhrase' => 'Method Not Allowed',
38 'protocolVersion' => '1.1',
39 'body' => '{"httpCode":405,"httpReason":"Method Not Allowed"}',
40 ],
41 ],
42 ];
43 }
44
45 private static function makeUri( $path ) {
46 return new Uri( "http://www.example.com/rest$path" );
47 }
48
49 /** @dataProvider provideTestViaRouter */
50 public function testViaRouter( $requestInfo, $responseInfo ) {
51 $router = new Router(
52 [ __DIR__ . '/../testRoutes.json' ],
53 [],
54 '/rest',
55 new EmptyBagOStuff(),
56 new ResponseFactory() );
57 $request = new RequestData( $requestInfo );
58 $response = $router->execute( $request );
59 if ( isset( $responseInfo['statusCode'] ) ) {
60 $this->assertSame( $responseInfo['statusCode'], $response->getStatusCode() );
61 }
62 if ( isset( $responseInfo['reasonPhrase'] ) ) {
63 $this->assertSame( $responseInfo['reasonPhrase'], $response->getReasonPhrase() );
64 }
65 if ( isset( $responseInfo['protocolVersion'] ) ) {
66 $this->assertSame( $responseInfo['protocolVersion'], $response->getProtocolVersion() );
67 }
68 if ( isset( $responseInfo['body'] ) ) {
69 $this->assertSame( $responseInfo['body'], $response->getBody()->getContents() );
70 }
71 $this->assertSame(
72 [],
73 array_diff( array_keys( $responseInfo ), [
74 'statusCode',
75 'reasonPhrase',
76 'protocolVersion',
77 'body'
78 ] ),
79 '$responseInfo may not contain unknown keys' );
80 }
81 }