Passed
Push — master ( e44bbb...5bf3f3 )
by Timon
02:17
created

CursorTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace TBolier\RethinkQL\IntegrationTest\Query;
4
5
use TBolier\RethinkQL\IntegrationTest\BaseTestCase;
6
use TBolier\RethinkQL\Response\ResponseInterface;
7
8
class CursorTest extends BaseTestCase
9
{
10
    public function setUp()
11
    {
12
        parent::setUp();
13
14
        if (!\in_array('cursortest', $this->r()->db()->tableList()->run()->getData()[0], true)) {
15
            $this->r()->db()->tableCreate('cursortest')->run();
16
        }
17
    }
18
19
    public function tearDown()
20
    {
21
        if (\in_array('cursortest', $this->r()->db()->tableList()->run()->getData()[0], true)) {
22
            $this->r()->db()->tableDrop('cursortest')->run();
23
        }
24
25
        parent::tearDown();
26
    }
27
28
    /**
29
     * @throws \Exception
30
     */
31
    public function testCursor()
32
    {
33
        $this->insertDocuments();
34
35
        /**
36
         * @
37
         */
38
        $cursor = $this->r()
39
            ->table('cursortest')
40
            ->run();
41
42
        $this->assertCount(1000, $cursor);
43
    }
44
45
    /**
46
     * @return ResponseInterface
47
     * @throws \Exception
48
     */
49
    private function insertDocuments(): ResponseInterface
50
    {
51
        $documents = [];
52
53
        for ($i = 1; $i <= 1000; $i++) {
54
            $documents[] = [
55
                'documentId' => $i,
56
                'title' => 'Test document',
57
                'description' => 'My first document.',
58
            ];
59
        }
60
61
        /** @var ResponseInterface $res */
62
        $res = $this->r()
63
            ->table('cursortest')
64
            ->insert([$documents])
65
            ->run();
66
67
        $this->assertEquals(1000, $res->getData()[0]['inserted']);
68
69
        return $res;
70
    }
71
}
72