Passed
Push — master ( 2f6a1e...868687 )
by Timon
04:41
created

AbstractTableTest::tearDown()   A

Complexity

Conditions 3
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 3
eloc 4
nc 2
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Query;
5
6
use TBolier\RethinkQL\IntegrationTest\AbstractTestCase;
7
use TBolier\RethinkQL\Response\ResponseInterface;
8
9
abstract class AbstractTableTest extends AbstractTestCase
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        $res = $this->r()->db()->tableList()->run();
16
        if (\is_array($res->getData()) && !\in_array('tabletest', $res->getData(), true)) {
17
            $this->r()->db()->tableCreate('tabletest')->run();
18
        }
19
    }
20
21
    public function tearDown()
22
    {
23
        $res = $this->r()->db()->tableList()->run();
24
        if (\is_array($res->getData()) && \in_array('tabletest', $res->getData(), true)) {
25
            $this->r()->db()->tableDrop('tabletest')->run();
26
        }
27
28
        parent::tearDown();
29
    }
30
31
32
    /**
33
     * @param int $documentId
34
     * @return ResponseInterface
35
     */
36
    protected function insertDocument(int $documentId): ResponseInterface
37
    {
38
        $res = $this->r()
39
            ->table('tabletest')
40
            ->insert([
41
                'id' => $documentId,
42
                'title' => 'Test document '.$documentId,
43
                'description' => 'A document description.',
44
            ])
45
            ->run();
46
47
        return $res;
48
    }
49
}
50