Completed
Pull Request — master (#30)
by Harry
02:53 queued 01:19
created

ResponseTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of Guzzle HTTP JSON-RPC
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE
11
 * @link http://github.com/graze/guzzle-jsonrpc
12
 */
13
namespace Graze\GuzzleHttp\JsonRpc\Message;
14
15
use Graze\GuzzleHttp\JsonRpc\ClientInterface;
16
use Graze\GuzzleHttp\JsonRpc\Test\UnitTestCase;
17
18
class ResponseTest extends UnitTestCase
19
{
20
    public function setUp()
21
    {
22
        $this->stream = $this->mockStream();
0 ignored issues
show
Bug introduced by
The property stream does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
    }
24
25
    public function testInterface()
26
    {
27
        $this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Message\ResponseInterface', new Response(200));
28
        $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', new Response(200));
29
    }
30
31
    public function testGetRpcId()
32
    {
33
        $response = new Response(200, [], json_encode([
34
            'id' => 123
35
        ]));
36
37
        $this->assertEquals(123, $response->getRpcId());
38
    }
39
40
    public function testGetRpcIdIsNull()
41
    {
42
        $response = new Response(200);
43
44
        $this->assertNull($response->getRpcId());
45
    }
46
47 View Code Duplication
    public function testGetRpcErrorCode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $response = new Response(200, [], json_encode([
50
            'error' => ['code'=>123]
51
        ]));
52
53
        $this->assertEquals(123, $response->getRpcErrorCode());
54
    }
55
56
    public function testGetRpcErrorCodeIsNull()
57
    {
58
        $response = new Response(200);
59
60
        $this->assertNull($response->getRpcErrorCode());
61
    }
62
63
    public function testGetRpcErrorMessage()
64
    {
65
        $response = new Response(200, [], json_encode([
66
            'error' => ['message'=>'foo']
67
        ]));
68
69
        $this->assertEquals('foo', $response->getRpcErrorMessage());
70
    }
71
72
    public function testGetRpcErrorMessageIsNull()
73
    {
74
        $response = new Response(200);
75
76
        $this->assertNull($response->getRpcErrorMessage());
77
    }
78
79 View Code Duplication
    public function testGetRpcErrorData()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $response = new Response(200, [], json_encode([
82
            'error' => ['data' => []]
83
        ]));
84
85
        $this->assertEquals([], $response->getRpcErrorData());
86
    }
87
88
    public function testGetRpcErrorDataIsNull()
89
    {
90
        $response = new Response(200);
91
92
        $this->assertNull($response->getRpcErrorData());
93
    }
94
95
    public function testGetRpcResult()
96
    {
97
        $response = new Response(200, [], json_encode([
98
            'result' => 'foo'
99
        ]));
100
101
        $this->assertEquals('foo', $response->getRpcResult());
102
    }
103
104
    public function testGetRpcResultIsNull()
105
    {
106
        $response = new Response(200);
107
108
        $this->assertNull($response->getRpcResult());
109
    }
110
111 View Code Duplication
    public function testGetRpcVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $response = new Response(200, [], json_encode([
114
            'jsonrpc' => 'foo'
115
        ]));
116
117
        $this->assertEquals('foo', $response->getRpcVersion());
118
    }
119
120
    public function testGetRpcVersionIsNull()
121
    {
122
        $response = new Response(200);
123
124
        $this->assertNull($response->getRpcVersion());
125
    }
126
}
127