Passed
Pull Request — master (#14)
by Timon
02:48
created

ConnectionQueryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 77
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testWriteQuery() 0 20 2
B testStopQuery() 0 26 2
B testContinueQuery() 0 26 2
1
<?php
2
3
namespace TBolier\RethinkQL\UnitTest\Connection;
4
5
use TBolier\RethinkQL\Query\MessageInterface;
6
use TBolier\RethinkQL\Response\ResponseInterface;
7
use TBolier\RethinkQL\Types\Response\ResponseType;
8
use TBolier\RethinkQL\UnitTest\BaseUnitTestCase;
9
10
class ConnectionQueryTest extends BaseConnectionTestCase
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