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

RequestExceptionTest::testCreateServerException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 11
loc 11
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
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
14
namespace Graze\GuzzleHttp\JsonRpc\Exception;
15
16
use Graze\GuzzleHttp\JsonRpc\Test\UnitTestCase;
17
18
class RequestExceptionTest extends UnitTestCase
19
{
20
    /** @var mixed */
21
    private $request;
22
    /** @var mixed */
23
    private $response;
24
25
    public function setUp()
26
    {
27
        $this->request = $this->mockRequest();
28
        $this->response = $this->mockResponse();
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function dataCreateClientException()
35
    {
36
        return [[-32600], [-32601], [-32602], [-32700]];
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function dataCreateServerException()
43
    {
44
        return [[-32603], [-32000], [-32099], [-10000]];
45
    }
46
47
    /**
48
     * @dataProvider dataCreateClientException
49
     *
50
     * @param int $code
51
     */
52 View Code Duplication
    public function testCreateClientException($code)
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...
53
    {
54
        $this->request->shouldReceive('getRequestTarget')->once()->withNoArgs()->andReturn('http://foo');
55
        $this->request->shouldReceive('getRpcMethod')->once()->withNoArgs()->andReturn('foo');
56
        $this->response->shouldReceive('getRpcErrorCode')->once()->withNoArgs()->andReturn($code);
57
        $this->response->shouldReceive('getRpcErrorMessage')->once()->withNoArgs()->andReturn('bar');
58
        $this->response->shouldReceive('getStatusCode')->once()->withNoArgs()->andReturn(200);
59
60
        $exception = RequestException::create($this->request, $this->response);
61
        $this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Exception\ClientException', $exception);
62
    }
63
64
    /**
65
     * @dataProvider dataCreateServerException
66
     *
67
     * @param int $code
68
     */
69 View Code Duplication
    public function testCreateServerException($code)
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...
70
    {
71
        $this->request->shouldReceive('getRequestTarget')->once()->withNoArgs()->andReturn('http://foo');
72
        $this->request->shouldReceive('getRpcMethod')->once()->withNoArgs()->andReturn('foo');
73
        $this->response->shouldReceive('getRpcErrorCode')->once()->withNoArgs()->andReturn($code);
74
        $this->response->shouldReceive('getRpcErrorMessage')->once()->withNoArgs()->andReturn('bar');
75
        $this->response->shouldReceive('getStatusCode')->once()->withNoArgs()->andReturn(200);
76
77
        $exception = RequestException::create($this->request, $this->response);
78
        $this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Exception\ServerException', $exception);
79
    }
80
}
81