Test Failed
Pull Request — master (#34)
by Timon
06:34
created

AbstractTableTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 8 3
A setUp() 0 7 3
A insertDocument() 0 12 1
A insertDocumentWithNumber() 0 13 1
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
     * @param int|string $id
33
     * @return ResponseInterface
34
     */
35
    protected function insertDocument($id): ResponseInterface
36
    {
37
        $res = $this->r()
38
            ->table('tabletest')
39
            ->insert([
40
                'id' => $id,
41
                'title' => 'Test document '.$id,
42
                'description' => 'A document description.',
43
            ])
44
            ->run();
45
46
        return $res;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $res could return the type iterable which is incompatible with the type-hinted return TBolier\RethinkQL\Response\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
47
    }
48
49
    /**
50
     * @param int|string $id
51
     * @param int $number
52
     * @return ResponseInterface
53
     */
54
    protected function insertDocumentWithNumber($id, int $number): ResponseInterface
55
    {
56
        $res = $this->r()
57
            ->table('tabletest')
58
            ->insert([
59
                'id' => $id,
60
                'title' => 'Test document '.$id,
61
                'number' => $number,
62
                'description' => 'A document description.',
63
            ])
64
            ->run();
65
66
        return $res;
67
    }
68
}
69