Completed
Pull Request — master (#7)
by Louis
20:12 queued 01:16
created

ResponseTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testResponse() 0 26 1
B jsonResponseProvider() 0 41 1
1
<?php
2
3
namespace EtherpadLite\Tests;
4
5
class ResponseTest extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * @dataProvider jsonResponseProvider
9
     */
10
    public function testResponse($rawResponse, $expected)
11
    {
12
        $httpResponse = $this->getMockBuilder('\Psr\Http\Message\ResponseInterface')
13
            ->setConstructorArgs([200, null, $rawResponse])
14
            ->getMock();
15
16
        $httpResponse
17
            ->expects($this->once())
18
            ->method('getStatusCode')
19
            ->will($this->returnValue(200));
20
21
        $httpResponse
22
            ->expects($this->once())
23
            ->method('getBody')
24
            ->will($this->returnValue($rawResponse));
25
26
        $response = new \EtherpadLite\Response($httpResponse);
27
28
        $this->assertNotEmpty($response->getResponse());
29
        $this->assertArrayHasKey('code', $response->getResponse());
30
        $this->assertArrayHasKey('message', $response->getResponse());
31
        $this->assertArrayHasKey('data', $response->getResponse());
32
        $this->assertEquals($expected['code'], $response->getCode());
33
        $this->assertEquals($expected['message'], $response->getMessage());
34
        $this->assertEquals($expected['data'], $response->getData());
35
    }
36
37
    public function jsonResponseProvider()
38
    {
39
        return [
40
            [
41
                '{"code":0,"message":"ok","data":{"groupID": "g.s8oes9dhwrvt0zif"}}',
42
                [
43
                    'code' => 0,
44
                    'message' => 'ok',
45
                    'data' => [
46
                        'groupID' => 'g.s8oes9dhwrvt0zif'
47
                    ]
48
                ]
49
            ],
50
            [
51
                '{"code":0,"message":"ok","data":{"padIDs":["g.OTeVWJ4KuZyRBlDI$aaa","meinNEUESPad","sjImkoFqDK","t08dXmHh1t"]}}',
52
                [
53
                    'code' => 0,
54
                    'message' => 'ok',
55
                    'data' => [
56
                        'padIDs' => ['g.OTeVWJ4KuZyRBlDI$aaa','meinNEUESPad','sjImkoFqDK','t08dXmHh1t']
57
                    ]
58
                ]
59
            ],
60
            [
61
                '{"code":4,"message":"no or wrong API Key","data":null}',
62
                [
63
                    'code' => 4,
64
                    'message' => 'no or wrong API Key',
65
                    'data' => null
66
                ]
67
            ],
68
            [
69
                '{"code":0,"message":"ok","data":null}',
70
                [
71
                    'code' => 0,
72
                    'message' => 'ok',
73
                    'data' => null
74
                ]
75
            ],
76
        ];
77
    }
78
}
79