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

AbstractTableTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A insertDocument() 0 12 1
A tearDown() 0 8 3
A setUp() 0 7 3
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