Passed
Push — master ( 9e6879...fd4e7d )
by Timon
03:32
created

DeleteTest::tearDown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkConnect\Test\Connection;
5
6
use ArrayObject;
7
use TBolier\RethinkQL\Response\Cursor;
8
use TBolier\RethinkQL\Response\ResponseInterface;
9
use TBolier\RethinkQL\IntegrationTest\BaseTestCase;
10
11
class DeleteTest extends BaseTestCase
12
{
13
    public function setUp()
14
    {
15
        parent::setUp();
16
17
        if (!\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) {
0 ignored issues
show
Bug introduced by
It seems like $this->r()->db()->tableList()->run()->getData() can also be of type string; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        if (!\in_array('tabletest', /** @scrutinizer ignore-type */ $this->r()->db()->tableList()->run()->getData(), true)) {
Loading history...
18
            $this->r()->db()->tableCreate('tabletest')->run();
19
        }
20
    }
21
22
    public function tearDown()
23
    {
24
        if (\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) {
0 ignored issues
show
Bug introduced by
It seems like $this->r()->db()->tableList()->run()->getData() can also be of type string; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        if (\in_array('tabletest', /** @scrutinizer ignore-type */ $this->r()->db()->tableList()->run()->getData(), true)) {
Loading history...
25
            $this->r()->db()->tableDrop('tabletest')->run();
26
        }
27
28
        parent::tearDown();
29
    }
30
31
    /**
32
     * @throws \Exception
33
     */
34
    public function testDeleteDocument()
35
    {
36
        $this->r()
37
            ->table('tabletest')
38
            ->insert([
39
                [
40
                    'title' => 'Delete document',
41
                ],
42
            ])
43
            ->run();
44
45
        /** @var ResponseInterface $count */
46
        $count = $this->r()
47
            ->table('tabletest')
48
            ->filter([
49
                [
50
                    'title' => 'Delete document',
51
                ],
52
            ])
53
            ->count()
54
            ->run();
55
56
        $this->assertInternalType('int', $count->getData());
57
58
        /** @var ResponseInterface $res */
59
        $res = $this->r()
60
            ->table('tabletest')
61
            ->filter([
62
                [
63
                    'title' => 'Delete document',
64
                ],
65
            ])
66
            ->delete()
67
            ->run();
68
69
        $this->assertObStatus(['deleted' => $count->getData()], $res->getData());
70
    }
71
}
72