Passed
Pull Request — master (#74)
by Timon
02:43
created

ChangesTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 38
dl 0
loc 67
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testChangesUpdates() 0 27 3
A testChangesCreate() 0 29 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Operation;
5
6
use TBolier\RethinkQL\Response\ResponseInterface;
7
8
class ChangesTest extends AbstractTableTest
9
{
10
    /**
11
     * @throws \Exception
12
     */
13
    public function testChangesCreate()
14
    {
15
        set_time_limit(5);
16
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);
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()
49
    {
50
        set_time_limit(5);
51
52
        $feed = $this->r()
53
            ->table('tabletest')
54
            ->changes()
55
            ->run();
56
57
        $this->insertDocument(777);
58
59
        $this->r()->table('tabletest')->filter(['id' => 777])->update(['description' => 'cool!'])->run();
60
61
        /** @var ResponseInterface $res */
62
        $i = 777;
63
        $old_val = $new_val = [];
64
        foreach ($feed as $change) {
65
            extract($change);
66
67
            if ($old_val !== null) {
68
                $this->assertEquals('A document description.', $old_val['description']);
69
                $this->assertEquals('cool!', $new_val['description']);
70
71
                break;
72
            } else {
73
                $this->assertEmpty($old_val);
74
                $this->assertEquals($i, $new_val['id']);
75
            }
76
        }
77
    }
78
}
79