Passed
Push — master ( 2f6a1e...868687 )
by Timon
04:41
created

UpdateTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilterUpdateWithMultipleDocuments() 0 16 1
B testUpdate() 0 24 1
A testFilterUpdate() 0 16 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Query;
5
6
use TBolier\RethinkQL\Response\ResponseInterface;
7
8
class UpdateTest extends AbstractTableTest
9
{
10
    /**
11
     * @throws \Exception
12
     */
13
    public function testUpdate()
14
    {
15
        $this->insertDocument(1);
16
17
        $this->r()
18
            ->table('tabletest')
19
            ->insert(['title' => 'Update document'])
20
            ->run();
21
22
        /** @var ResponseInterface $count */
23
        $count = $this->r()
24
            ->table('tabletest')
25
            ->filter(['title' => 'Update document'])
26
            ->count()
27
            ->run();
28
29
        /** @var ResponseInterface $res */
30
        $res = $this->r()
31
            ->table('tabletest')
32
            ->filter(['title' => 'Update document'])
33
            ->update(['title' => 'Updated document'])
34
            ->run();
35
36
        $this->assertObStatus(['replaced' => $count->getData()], $res->getData());
37
    }
38
39
    /**
40
     * @throws \Exception
41
     */
42
    public function testFilterUpdate()
43
    {
44
        $this->insertDocument(1);
45
        $this->insertDocument(2);
46
        $this->insertDocument(3);
47
        $this->insertDocument(4);
48
        $this->insertDocument(5);
49
50
        /** @var ResponseInterface $res */
51
        $res = $this->r()
52
            ->table('tabletest')
53
            ->filter(['id' => 5])
54
            ->update(['title' => 'Updated document'])
55
            ->run();
56
57
        $this->assertObStatus(['replaced' => 1], $res->getData());
58
    }
59
60
    /**
61
     * @throws \Exception
62
     */
63
    public function testFilterUpdateWithMultipleDocuments()
64
    {
65
        $this->insertDocument(1);
66
        $this->insertDocument(2);
67
        $this->insertDocument(3);
68
        $this->insertDocument(4);
69
        $this->insertDocument(5);
70
71
        /** @var ResponseInterface $res */
72
        $res = $this->r()
73
            ->table('tabletest')
74
            ->filter(['description' => 'A document description.'])
75
            ->update(['title' => 'Updated document'])
76
            ->run();
77
78
        $this->assertObStatus(['replaced' => 5], $res->getData());
79
    }
80
}
81