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 GetAllTest extends AbstractTableTest |
||||
10 | { |
||||
11 | /** |
||||
12 | * @return void |
||||
13 | * @throws \Exception |
||||
14 | */ |
||||
15 | public function testGetAll(): void |
||||
16 | { |
||||
17 | $this->insertDocument(1); |
||||
18 | $this->insertDocument('stringId'); |
||||
19 | |||||
20 | /** @var Cursor $cursor */ |
||||
21 | $cursor = $this->r() |
||||
22 | ->table('tabletest') |
||||
23 | ->getAll(1, 'stringId') |
||||
24 | ->run(); |
||||
25 | |||||
26 | /** @var array $array */ |
||||
27 | $array = $cursor->current(); |
||||
28 | |||||
29 | $this->assertArraySubset(['description' => 'A document description.'], $array); |
||||
0 ignored issues
–
show
|
|||||
30 | } |
||||
31 | |||||
32 | /** |
||||
33 | * @return void |
||||
34 | * @throws \Exception |
||||
35 | */ |
||||
36 | public function testGetAllAndIsEmpty(): void |
||||
37 | { |
||||
38 | $this->insertDocument(1); |
||||
39 | $this->insertDocument('stringId'); |
||||
40 | |||||
41 | /** @var ResponseInterface $res */ |
||||
42 | $res = $this->r() |
||||
43 | ->table('tabletest') |
||||
44 | ->getAll(1, 'stringId') |
||||
45 | ->isEmpty() |
||||
46 | ->run(); |
||||
47 | |||||
48 | $this->assertFalse($res->getData()); |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * @return void |
||||
53 | * @throws \Exception |
||||
54 | */ |
||||
55 | public function testGetAllAndCount(): void |
||||
56 | { |
||||
57 | $this->insertDocument(1); |
||||
58 | $this->insertDocument('stringId'); |
||||
59 | |||||
60 | /** @var ResponseInterface $res */ |
||||
61 | $res = $this->r() |
||||
62 | ->table('tabletest') |
||||
63 | ->getAll(1, 'stringId') |
||||
64 | ->count() |
||||
65 | ->run(); |
||||
66 | |||||
67 | $this->assertEquals(2, $res->getData()); |
||||
68 | } |
||||
69 | |||||
70 | /** |
||||
71 | * @return void |
||||
72 | * @throws \Exception |
||||
73 | */ |
||||
74 | public function testGetAllAndAvg(): void |
||||
75 | { |
||||
76 | $this->insertDocumentWithNumber(1, 50); |
||||
77 | $this->insertDocumentWithNumber(2, 100); |
||||
78 | |||||
79 | /** @var ResponseInterface $res */ |
||||
80 | $res = $this->r() |
||||
81 | ->table('tabletest') |
||||
82 | ->getAll(1, 2) |
||||
83 | ->avg('number') |
||||
84 | ->run(); |
||||
85 | |||||
86 | $this->assertEquals(75, $res->getData()); |
||||
87 | } |
||||
88 | |||||
89 | /** |
||||
90 | * @return void |
||||
91 | * @throws \Exception |
||||
92 | */ |
||||
93 | public function testGetAllAndSum(): void |
||||
94 | { |
||||
95 | $this->insertDocumentWithNumber(1, 50); |
||||
96 | $this->insertDocumentWithNumber(2, 100); |
||||
97 | |||||
98 | /** @var ResponseInterface $res */ |
||||
99 | $res = $this->r() |
||||
100 | ->table('tabletest') |
||||
101 | ->getAll(1, 2) |
||||
102 | ->sum('number') |
||||
103 | ->run(); |
||||
104 | |||||
105 | $this->assertEquals(150, $res->getData()); |
||||
106 | } |
||||
107 | |||||
108 | /** |
||||
109 | * @return void |
||||
110 | * @throws \Exception |
||||
111 | */ |
||||
112 | public function testGetAllAndLimit(): void |
||||
113 | { |
||||
114 | $this->insertDocument(1); |
||||
115 | $this->insertDocument('stringId'); |
||||
116 | |||||
117 | /** @var ResponseInterface $res */ |
||||
118 | $cursor = $this->r() |
||||
119 | ->table('tabletest') |
||||
120 | ->getAll(1, 'stringId') |
||||
121 | ->limit(1) |
||||
122 | ->run(); |
||||
123 | |||||
124 | $this->assertCount(1, $cursor); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * @return void |
||||
129 | * @throws \Exception |
||||
130 | */ |
||||
131 | public function testGetAllAndSkip(): void |
||||
132 | { |
||||
133 | $this->insertDocument(1); |
||||
134 | $this->insertDocument('stringId'); |
||||
135 | |||||
136 | /** @var ResponseInterface $res */ |
||||
137 | $cursor = $this->r() |
||||
138 | ->table('tabletest') |
||||
139 | ->getAll(1, 'stringId') |
||||
140 | ->skip(1) |
||||
141 | ->run(); |
||||
142 | |||||
143 | $this->assertCount(1, $cursor); |
||||
144 | } |
||||
145 | |||||
146 | /** |
||||
147 | * @return void |
||||
148 | * @throws \Exception |
||||
149 | */ |
||||
150 | public function testGetAllAndOrderBy(): void |
||||
151 | { |
||||
152 | $this->insertDocument(1); |
||||
153 | $this->insertDocument('stringId'); |
||||
154 | |||||
155 | /** @var ResponseInterface $res */ |
||||
156 | $res = $this->r() |
||||
157 | ->table('tabletest') |
||||
158 | ->getAll(1, 'stringId') |
||||
159 | ->orderBy($this->r()->desc('id')) |
||||
160 | ->run(); |
||||
161 | |||||
162 | $this->assertArraySubset(['id' => 'stringId'], $res->getData()[0]); |
||||
0 ignored issues
–
show
The function
PHPUnit\Framework\Assert::assertArraySubset() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3494
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
163 | } |
||||
164 | |||||
165 | /** |
||||
166 | * @return void |
||||
167 | * @throws \Exception |
||||
168 | */ |
||||
169 | public function testGetAllAndMin(): void |
||||
170 | { |
||||
171 | $this->insertDocumentWithNumber(1, 77); |
||||
172 | $this->insertDocumentWithNumber(2, 99); |
||||
173 | |||||
174 | /** @var ResponseInterface $res */ |
||||
175 | $res = $this->r() |
||||
176 | ->table('tabletest') |
||||
177 | ->getAll(1, 2) |
||||
178 | ->min('number') |
||||
179 | ->run(); |
||||
180 | |||||
181 | $this->assertArraySubset(['number' => 77], $res->getData()); |
||||
0 ignored issues
–
show
The function
PHPUnit\Framework\Assert::assertArraySubset() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3494
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
182 | } |
||||
183 | |||||
184 | /** |
||||
185 | * @return void |
||||
186 | * @throws \Exception |
||||
187 | */ |
||||
188 | public function testGetAllAndMax(): void |
||||
189 | { |
||||
190 | $this->insertDocumentWithNumber(1, 77); |
||||
191 | $this->insertDocumentWithNumber(2, 99); |
||||
192 | |||||
193 | /** @var ResponseInterface $res */ |
||||
194 | $res = $this->r() |
||||
195 | ->table('tabletest') |
||||
196 | ->getAll(1, 2) |
||||
197 | ->max('number') |
||||
198 | ->run(); |
||||
199 | |||||
200 | $this->assertArraySubset(['number' => 99], $res->getData()); |
||||
0 ignored issues
–
show
The function
PHPUnit\Framework\Assert::assertArraySubset() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3494
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
201 | } |
||||
202 | } |
||||
203 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.