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