Passed
Pull Request — master (#34)
by Marc
07:28
created

FilterTest::testFilterAndSum()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Query;
5
6
use TBolier\RethinkQL\Response\Cursor;
7
use TBolier\RethinkQL\Response\ResponseInterface;
8
9
class FilterTest extends AbstractTableTest
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function testFilter()
15
    {
16
        $this->insertDocument(1);
17
18
        /** @var Cursor $cursor */
19
        $cursor = $this->r()
20
            ->table('tabletest')
21
            ->filter(['title' => 'Test document 1'])
22
            ->run();
23
24
        /** @var array $array */
25
        $array = $cursor->current();
26
27
        $this->assertInstanceOf(\Iterator::class, $cursor);
28
        $this->assertArraySubset(['title' => 'Test document 1'], $array);
29
    }
30
31
    /**
32
     * @throws \Exception
33
     */
34
    public function testFilterOnMultipleDocuments()
35
    {
36
        $this->insertDocument(1);
37
        $this->insertDocument(2);
38
        $this->insertDocument(3);
39
        $this->insertDocument(4);
40
        $this->insertDocument(5);
41
42
        /** @var Cursor $cursor */
43
        $cursor = $this->r()
44
            ->table('tabletest')
45
            ->filter(['title' => 'Test document 1'])
46
            ->run();
47
48
        $this->assertCount(1, $cursor);
49
    }
50
51
    /**
52
     * @throws \Exception
53
     */
54
    public function testFilterAndAvg()
55
    {
56
        $this->insertDocument(1);
57
        $this->insertDocument(2);
58
        $this->insertDocument(3);
59
        $this->insertDocument(4);
60
        $this->insertDocument(5);
61
62
        /** @var ResponseInterface $cursor */
63
        $res = $this->r()
64
                       ->table('tabletest')
65
                       ->filter(['title' => 'Test document 1'])
66
                       ->avg('number')
67
                       ->run();
68
69
        $this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
70
    }
71
72
    /**
73
     * @throws \Exception
74
     */
75
    public function testFilterAndSum()
76
    {
77
        $this->insertDocument(1);
78
        $this->insertDocument(2);
79
        $this->insertDocument(3);
80
        $this->insertDocument(4);
81
        $this->insertDocument(5);
82
83
        /** @var ResponseInterface $cursor */
84
        $res = $this->r()
85
                    ->table('tabletest')
86
                    ->filter(['title' => 'Test document 1'])
87
                    ->sum('number')
88
                    ->run();
89
90
        $this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
91
    }
92
93
    /**
94
     * @throws \Exception
95
     */
96
    public function testFilterAndMin()
97
    {
98
        $this->insertDocument(1);
99
        $this->insertDocument(2);
100
        $this->insertDocument(3);
101
        $this->insertDocument(4);
102
        $this->insertDocument(5);
103
104
        /** @var ResponseInterface $cursor */
105
        $res = $this->r()
106
                    ->table('tabletest')
107
                    ->filter(['title' => 'Test document 1'])
108
                    ->min('number')
109
                    ->run();
110
111
        /** @var array $array */
112
        $array = $res->getData();
113
114
        $this->assertArraySubset(['description' => 'A document description.'], $array);
115
    }
116
117
    /**
118
     * @throws \Exception
119
     */
120
    public function testFilterAndMax()
121
    {
122
        $this->insertDocument(1);
123
        $this->insertDocument(2);
124
        $this->insertDocument(3);
125
        $this->insertDocument(4);
126
        $this->insertDocument(5);
127
128
        /** @var ResponseInterface $cursor */
129
        $res = $this->r()
130
                    ->table('tabletest')
131
                    ->filter(['title' => 'Test document 1'])
132
                    ->max('number')
133
                    ->run();
134
135
        /** @var array $array */
136
        $array = $res->getData();
137
138
        $this->assertArraySubset(['description' => 'A document description.'], $array);
139
    }
140
141
142
}
143