RequestExceptionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateServerException() 0 10 1
A testCreateClientException() 0 10 1
A dataCreateServerException() 0 3 1
A setUp() 0 4 1
A dataCreateClientException() 0 3 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
    public function testCreateClientException($code)
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
    public function testCreateServerException($code)
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