1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\UnitTest\Connection; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Message\MessageInterface; |
7
|
|
|
use TBolier\RethinkQL\Response\ResponseInterface; |
8
|
|
|
use TBolier\RethinkQL\Types\Response\ResponseType; |
9
|
|
|
|
10
|
|
|
class ConnectionQueryTest extends ConnectionTestCase |
11
|
|
|
{ |
12
|
|
|
public function testWriteQuery() |
13
|
|
|
{ |
14
|
|
|
$this->connect(); |
15
|
|
|
|
16
|
|
|
$token = 1; |
17
|
|
|
$message = \Mockery::mock(MessageInterface::class); |
18
|
|
|
$message->shouldReceive('setOptions')->once(); |
19
|
|
|
|
20
|
|
|
$this->stream->shouldReceive('write')->once()->andReturn(20); |
21
|
|
|
|
22
|
|
|
$this->querySerializer->shouldReceive('serialize')->atLeast()->andReturn("['serialized': true]"); |
23
|
|
|
|
24
|
|
|
try { |
25
|
|
|
$this->connection->writeQuery($token, $message); |
26
|
|
|
} catch (\Exception $e) { |
27
|
|
|
$this->fail($e->getMessage()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$this->assertTrue(true); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testStopQuery() |
34
|
|
|
{ |
35
|
|
|
$this->connect(); |
36
|
|
|
|
37
|
|
|
$token = 1; |
38
|
|
|
|
39
|
|
|
$response = \Mockery::mock(ResponseInterface::class); |
40
|
|
|
$response->shouldReceive('getType')->atLeast()->andReturn(ResponseType::SUCCESS_ATOM); |
41
|
|
|
|
42
|
|
|
$buffer = new \stdClass(); |
43
|
|
|
$this->catchStreamWrite($buffer); |
44
|
|
|
$this->catchStreamRead(4 + 8, $buffer); |
45
|
|
|
$this->catchStreamRead(20, $buffer); |
46
|
|
|
|
47
|
|
|
$this->querySerializer->shouldReceive('serialize')->once()->andReturn("['serialized': true]"); |
48
|
|
|
|
49
|
|
|
$this->responseSerializer->shouldReceive('deserialize')->once()->andReturn($response); |
50
|
|
|
|
51
|
|
|
try { |
52
|
|
|
$this->connection->stopQuery($token); |
53
|
|
|
} catch (\Exception $e) { |
54
|
|
|
$this->fail($e->getMessage()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->assertTrue(true); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testContinueQuery() |
61
|
|
|
{ |
62
|
|
|
$this->connect(); |
63
|
|
|
|
64
|
|
|
$token = 1; |
65
|
|
|
|
66
|
|
|
$response = \Mockery::mock(ResponseInterface::class); |
67
|
|
|
$response->shouldReceive('getType')->atLeast()->andReturn(ResponseType::SUCCESS_ATOM); |
68
|
|
|
|
69
|
|
|
$buffer = new \stdClass(); |
70
|
|
|
$this->catchStreamWrite($buffer); |
71
|
|
|
$this->catchStreamRead(4 + 8, $buffer); |
72
|
|
|
$this->catchStreamRead(20, $buffer); |
73
|
|
|
|
74
|
|
|
$this->querySerializer->shouldReceive('serialize')->once()->andReturn("['serialized': true]"); |
75
|
|
|
|
76
|
|
|
$this->responseSerializer->shouldReceive('deserialize')->once()->andReturn($response); |
77
|
|
|
|
78
|
|
|
try { |
79
|
|
|
$this->connection->continueQuery($token); |
80
|
|
|
} catch (\Exception $e) { |
81
|
|
|
$this->fail($e->getMessage()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->assertTrue(true); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|