|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Codeception\Test\Unit; |
|
4
|
|
|
use veejay\jsonrpc\batch\Response; |
|
5
|
|
|
|
|
6
|
|
|
class ResponseTest extends Unit |
|
7
|
|
|
{ |
|
8
|
|
|
public function testSetError() |
|
9
|
|
|
{ |
|
10
|
|
|
$response = new Response; |
|
11
|
|
|
$original = clone $response; |
|
12
|
|
|
|
|
13
|
|
|
$original->error = (object)['code' => Response::INTERNAL_ERROR, 'message' => 'some message']; |
|
14
|
|
|
$response->setError(Response::INTERNAL_ERROR, 'some message'); |
|
15
|
|
|
$this->assertEquals($original, $response); |
|
16
|
|
|
|
|
17
|
|
|
$original->error = (object)['code' => Response::METHOD_NOT_FOUND, 'message' => Response::getErrorMessage(Response::METHOD_NOT_FOUND)]; |
|
18
|
|
|
$self = $response->setError(Response::METHOD_NOT_FOUND); |
|
19
|
|
|
$this->assertEquals($original, $response); |
|
20
|
|
|
$this->assertEquals($self, $response); // Check that returned the same object |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testHasError() |
|
24
|
|
|
{ |
|
25
|
|
|
$response = new Response; |
|
26
|
|
|
$this->assertFalse($response->hasError()); |
|
27
|
|
|
|
|
28
|
|
|
$response->setError(Response::INVALID_PARAMS); |
|
29
|
|
|
$this->assertTrue($response->hasError()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testResetError() |
|
33
|
|
|
{ |
|
34
|
|
|
$response = new Response; |
|
35
|
|
|
$response->setError(Response::INVALID_PARAMS); |
|
36
|
|
|
$response->resetError(); |
|
37
|
|
|
$this->assertFalse($response->hasError()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testGetData() |
|
41
|
|
|
{ |
|
42
|
|
|
// TODO: ??? |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testIsNotification() |
|
46
|
|
|
{ |
|
47
|
|
|
$response = new Response; |
|
48
|
|
|
|
|
49
|
|
|
$wrong = [true, false, 0, 1, '', 'null', []]; |
|
50
|
|
|
foreach ($wrong as $value) { |
|
51
|
|
|
$response->id = $value; |
|
52
|
|
|
$this->assertFalse($response->isNotification()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$response->id = null; |
|
56
|
|
|
$this->assertTrue($response->isNotification()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetErrorMessage() |
|
60
|
|
|
{ |
|
61
|
|
|
$message = Response::getErrorMessage(Response::INVALID_PARAMS); |
|
62
|
|
|
$this->assertEquals(Response::$errors[Response::INVALID_PARAMS], $message); |
|
63
|
|
|
|
|
64
|
|
|
$message = Response::getErrorMessage(1234567890); |
|
65
|
|
|
$this->assertEquals(Response::DEFAULT_ERROR, $message); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|