Failed Conditions
Pull Request — master (#74)
by Timon
02:38
created

ChangesTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 63
dl 0
loc 115
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testChangesUpdates() 0 25 3
A testChangesCreate() 0 28 3
A testChangesWithOptions() 0 18 1
A testChangesCreateWithFilter() 0 21 1
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
        $old_val = $new_val = [];
92
        $change = $feed->current();
93
        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

93
        extract(/** @scrutinizer ignore-type */ $change);
Loading history...
94
95
        $this->assertEmpty($old_val);
96
        $this->assertEquals(1, $new_val['id']);
97
        $this->assertEquals('cool!', $new_val['description']);
98
    }
99
100
    /**
101
     * @throws \Exception
102
     */
103
    public function testChangesCreateWithFilter(): void
104
    {
105
        /** @var Cursor $feed */
106
        $feed = $this->r()
107
            ->table('tabletest')
108
            ->filter(['id' => 4])
109
            ->changes()
110
            ->run();
111
112
        $this->insertDocument(1);
113
        $this->insertDocument(2);
114
        $this->insertDocument(3);
115
        $this->insertDocument(4);
116
        $this->insertDocument(5);
117
118
        $old_val = $new_val = [];
119
        $change = $feed->current();
120
        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

120
        extract(/** @scrutinizer ignore-type */ $change);
Loading history...
121
122
        $this->assertEmpty($old_val);
123
        $this->assertEquals(4, $new_val['id']);
124
    }
125
}
126