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
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->request = $this->mockRequest(); |
|
|
|
|
23
|
|
|
$this->response = $this->mockResponse(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function dataCreateClientException() |
30
|
|
|
{ |
31
|
|
|
return [[-32600], [-32601], [-32602], [-32700]]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
public function dataCreateServerException() |
38
|
|
|
{ |
39
|
|
|
return [[-32603], [-32000], [-32099], [-10000]]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider dataCreateClientException |
44
|
|
|
* |
45
|
|
|
* @param int $code |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function testCreateClientException($code) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$this->request->shouldReceive('getRequestTarget')->once()->withNoArgs()->andReturn('http://foo'); |
50
|
|
|
$this->request->shouldReceive('getRpcMethod')->once()->withNoArgs()->andReturn('foo'); |
51
|
|
|
$this->response->shouldReceive('getRpcErrorCode')->once()->withNoArgs()->andReturn($code); |
52
|
|
|
$this->response->shouldReceive('getRpcErrorMessage')->once()->withNoArgs()->andReturn('bar'); |
53
|
|
|
$this->response->shouldReceive('getStatusCode')->once()->withNoArgs()->andReturn(200); |
54
|
|
|
|
55
|
|
|
$exception = RequestException::create($this->request, $this->response); |
56
|
|
|
$this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Exception\ClientException', $exception); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider dataCreateServerException |
61
|
|
|
* |
62
|
|
|
* @param int $code |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function testCreateServerException($code) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$this->request->shouldReceive('getRequestTarget')->once()->withNoArgs()->andReturn('http://foo'); |
67
|
|
|
$this->request->shouldReceive('getRpcMethod')->once()->withNoArgs()->andReturn('foo'); |
68
|
|
|
$this->response->shouldReceive('getRpcErrorCode')->once()->withNoArgs()->andReturn($code); |
69
|
|
|
$this->response->shouldReceive('getRpcErrorMessage')->once()->withNoArgs()->andReturn('bar'); |
70
|
|
|
$this->response->shouldReceive('getStatusCode')->once()->withNoArgs()->andReturn(200); |
71
|
|
|
|
72
|
|
|
$exception = RequestException::create($this->request, $this->response); |
73
|
|
|
$this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Exception\ServerException', $exception); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: