Failed Conditions
Pull Request — master (#74)
by Timon
03:06
created

ChangesTest::testChangesUpdates()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 25
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Operation;
5
6
use TBolier\RethinkQL\Response\Cursor;
7
use TBolier\RethinkQL\Response\ResponseInterface;
8
9
class ChangesTest extends AbstractTableTest
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function testChangesCreate(): void
15
    {
16
        /** @var Cursor $feed */
17
        $feed = $this->r()
18
            ->table('tabletest')
19
            ->changes()
20
            ->run();
21
22
        $this->insertDocument(1);
23
        $this->insertDocument(2);
24
        $this->insertDocument(3);
25
        $this->insertDocument(4);
26
        $this->insertDocument(5);
27
28
        /** @var ResponseInterface $res */
29
        $i = 1;
30
        $old_val = $new_val = [];
31
        foreach ($feed as $change) {
32
            extract($change);
0 ignored issues
show
Bug introduced by
It seems like $change can also be of type null and string; however, parameter $var_array of extract() 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

32
            extract(/** @scrutinizer ignore-type */ $change);
Loading history...
33
34
            $this->assertEmpty($old_val);
35
            $this->assertEquals($i, $new_val['id']);
36
37
            if ($i === 5) {
38
                break;
39
            }
40
41
            $i++;
42
        }
43
    }
44
45
    /**
46
     * @throws \Exception
47
     */
48
    public function testChangesUpdates(): void
49
    {
50
        /** @var Cursor $feed */
51
        $feed = $this->r()
52
            ->table('tabletest')
53
            ->changes()
54
            ->run();
55
56
        $this->insertDocument(777);
57
58
        $this->r()->table('tabletest')->filter(['id' => 777])->update(['description' => 'cool!'])->run();
59
60
        $i = 777;
61
        $old_val = $new_val = [];
62
        foreach ($feed as $change) {
63
            extract($change);
0 ignored issues
show
Bug introduced by
It seems like $change can also be of type null and string; however, parameter $var_array of extract() 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

63
            extract(/** @scrutinizer ignore-type */ $change);
Loading history...
64
65
            if ($old_val !== null) {
66
                $this->assertEquals('A document description.', $old_val['description']);
67
                $this->assertEquals('cool!', $new_val['description']);
68
69
                break;
70
            } else {
71
                $this->assertEmpty($old_val);
72
                $this->assertEquals($i, $new_val['id']);
73
            }
74
        }
75
    }
76
77
    /**
78
     * @throws \Exception
79
     */
80
    public function testChangesWithOptions(): void
81
    {
82
        /** @var Cursor $feed */
83
        $feed = $this->r()
84
            ->table('tabletest')
85
            ->changes(['squash' => true])
86
            ->run();
87
88
        $this->insertDocument(1);
89
        $this->r()->table('tabletest')->filter(['id' => 1])->update(['description' => 'cool!'])->run();
90
91
        $i = 1;
92
        $old_val = $new_val = [];
93
        $change = $feed->current();
94
        extract($change);
0 ignored issues
show
Bug introduced by
It seems like $change can also be of type null and string; however, parameter $var_array of extract() 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

94
        extract(/** @scrutinizer ignore-type */ $change);
Loading history...
95
96
        $this->assertEmpty($old_val);
97
        $this->assertEquals($i, $new_val['id']);
98
        $this->assertEquals('cool!', $new_val['description']);
99
    }
100
}
101