Completed
Push — master ( c4513b...cc10a3 )
by Harry
03:02
created

ResponseTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 112
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 112
rs 10
wmc 14
lcom 3
cbo 2

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testInterface() 0 5 1
A testGetRpcId() 0 8 1
A testGetRpcIdIsNull() 0 6 1
A testGetRpcErrorCode() 8 8 1
A testGetRpcErrorCodeIsNull() 0 6 1
A testGetRpcErrorMessage() 0 8 1
A testGetRpcErrorMessageIsNull() 0 6 1
A testGetRpcErrorDataIsNull() 0 6 1
A testGetRpcResult() 0 8 1
A testGetRpcResultIsNull() 0 6 1
A testGetRpcVersion() 8 8 1
A testGetRpcVersionIsNull() 0 6 1
A testGetRpcErrorData() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    /** @var mixed */
21
    private $stream;
22
23
    public function setUp()
24
    {
25
        $this->stream = $this->mockStream();
26
    }
27
28
    public function testInterface()
29
    {
30
        $this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Message\ResponseInterface', new Response(200));
31
        $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', new Response(200));
32
    }
33
34
    public function testGetRpcId()
35
    {
36
        $response = new Response(200, [], json_encode([
37
            'id' => 123
38
        ]));
39
40
        $this->assertEquals(123, $response->getRpcId());
41
    }
42
43
    public function testGetRpcIdIsNull()
44
    {
45
        $response = new Response(200);
46
47
        $this->assertNull($response->getRpcId());
48
    }
49
50 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...
51
    {
52
        $response = new Response(200, [], json_encode([
53
            'error' => ['code'=>123]
54
        ]));
55
56
        $this->assertEquals(123, $response->getRpcErrorCode());
57
    }
58
59
    public function testGetRpcErrorCodeIsNull()
60
    {
61
        $response = new Response(200);
62
63
        $this->assertNull($response->getRpcErrorCode());
64
    }
65
66
    public function testGetRpcErrorMessage()
67
    {
68
        $response = new Response(200, [], json_encode([
69
            'error' => ['message'=>'foo']
70
        ]));
71
72
        $this->assertEquals('foo', $response->getRpcErrorMessage());
73
    }
74
75
    public function testGetRpcErrorMessageIsNull()
76
    {
77
        $response = new Response(200);
78
79
        $this->assertNull($response->getRpcErrorMessage());
80
    }
81
82 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...
83
    {
84
        $response = new Response(200, [], json_encode([
85
            'error' => ['data' => []]
86
        ]));
87
88
        $this->assertEquals([], $response->getRpcErrorData());
89
    }
90
91
    public function testGetRpcErrorDataIsNull()
92
    {
93
        $response = new Response(200);
94
95
        $this->assertNull($response->getRpcErrorData());
96
    }
97
98
    public function testGetRpcResult()
99
    {
100
        $response = new Response(200, [], json_encode([
101
            'result' => 'foo'
102
        ]));
103
104
        $this->assertEquals('foo', $response->getRpcResult());
105
    }
106
107
    public function testGetRpcResultIsNull()
108
    {
109
        $response = new Response(200);
110
111
        $this->assertNull($response->getRpcResult());
112
    }
113
114 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...
115
    {
116
        $response = new Response(200, [], json_encode([
117
            'jsonrpc' => 'foo'
118
        ]));
119
120
        $this->assertEquals('foo', $response->getRpcVersion());
121
    }
122
123
    public function testGetRpcVersionIsNull()
124
    {
125
        $response = new Response(200);
126
127
        $this->assertNull($response->getRpcVersion());
128
    }
129
}
130