| Total Complexity | 16 |
| Total Lines | 308 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class FilterTest extends AbstractTableTest |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @throws \Exception |
||
| 13 | */ |
||
| 14 | public function testFilter() |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @throws \Exception |
||
| 33 | */ |
||
| 34 | public function testFilterOnMultipleDocuments() |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return void |
||
| 53 | * @throws \Exception |
||
| 54 | */ |
||
| 55 | public function testFilterAndIsEmpty(): void |
||
| 56 | { |
||
| 57 | $this->insertDocument(1); |
||
| 58 | $this->insertDocument('stringId'); |
||
| 59 | |||
| 60 | /** @var ResponseInterface $res */ |
||
| 61 | $res = $this->r() |
||
| 62 | ->table('tabletest') |
||
| 63 | ->filter(['id' => 1]) |
||
| 64 | ->isEmpty() |
||
| 65 | ->run(); |
||
| 66 | |||
| 67 | $this->assertFalse($res->getData()); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return void |
||
| 72 | * @throws \Exception |
||
| 73 | */ |
||
| 74 | public function testFilterAndCount(): void |
||
| 75 | { |
||
| 76 | $this->insertDocument(1); |
||
| 77 | $this->insertDocument('stringId'); |
||
| 78 | |||
| 79 | /** @var ResponseInterface $res */ |
||
| 80 | $res = $this->r() |
||
| 81 | ->table('tabletest') |
||
| 82 | ->filter(['description' => 'A document description.']) |
||
| 83 | ->count() |
||
| 84 | ->run(); |
||
| 85 | |||
| 86 | $this->assertEquals(2, $res->getData()); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return void |
||
| 91 | * @throws \Exception |
||
| 92 | */ |
||
| 93 | public function testFilterAndAvg(): 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 | ->filter(['description' => 'A document description.']) |
||
| 102 | ->avg('number') |
||
| 103 | ->run(); |
||
| 104 | |||
| 105 | $this->assertEquals(75, $res->getData()); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return void |
||
| 110 | * @throws \Exception |
||
| 111 | */ |
||
| 112 | public function testFilterAndSum(): void |
||
| 113 | { |
||
| 114 | $this->insertDocumentWithNumber(1, 50); |
||
| 115 | $this->insertDocumentWithNumber(2, 100); |
||
| 116 | |||
| 117 | /** @var ResponseInterface $res */ |
||
| 118 | $res = $this->r() |
||
| 119 | ->table('tabletest') |
||
| 120 | ->filter(['description' => 'A document description.']) |
||
| 121 | ->sum('number') |
||
| 122 | ->run(); |
||
| 123 | |||
| 124 | $this->assertEquals(150, $res->getData()); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return void |
||
| 129 | * @throws \Exception |
||
| 130 | */ |
||
| 131 | public function testFilterAndLimit(): void |
||
| 132 | { |
||
| 133 | $this->insertDocument(1); |
||
| 134 | $this->insertDocument('stringId'); |
||
| 135 | |||
| 136 | /** @var ResponseInterface $res */ |
||
| 137 | $cursor = $this->r() |
||
| 138 | ->table('tabletest') |
||
| 139 | ->filter(['description' => 'A document description.']) |
||
| 140 | ->limit(1) |
||
| 141 | ->run(); |
||
| 142 | |||
| 143 | $this->assertCount(1, $cursor); |
||
|
1 ignored issue
–
show
|
|||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return void |
||
| 148 | * @throws \Exception |
||
| 149 | */ |
||
| 150 | public function testFilterAndSkip(): void |
||
| 151 | { |
||
| 152 | $this->insertDocument(1); |
||
| 153 | $this->insertDocument('stringId'); |
||
| 154 | |||
| 155 | /** @var ResponseInterface $res */ |
||
| 156 | $cursor = $this->r() |
||
| 157 | ->table('tabletest') |
||
| 158 | ->filter(['description' => 'A document description.']) |
||
| 159 | ->skip(1) |
||
| 160 | ->run(); |
||
| 161 | |||
| 162 | $this->assertCount(1, $cursor); |
||
|
1 ignored issue
–
show
|
|||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return void |
||
| 167 | * @throws \Exception |
||
| 168 | */ |
||
| 169 | public function testFilterAndOrderBy(): void |
||
| 170 | { |
||
| 171 | $this->insertDocument(1); |
||
| 172 | $this->insertDocument('stringId'); |
||
| 173 | |||
| 174 | /** @var ResponseInterface $res */ |
||
| 175 | $res = $this->r() |
||
| 176 | ->table('tabletest') |
||
| 177 | ->filter(['description' => 'A document description.']) |
||
| 178 | ->orderBy($this->r()->desc('id')) |
||
| 179 | ->run(); |
||
| 180 | |||
| 181 | $this->assertArraySubset(['id' => 'stringId'], $res->getData()[0]); |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return void |
||
| 186 | * @throws \Exception |
||
| 187 | */ |
||
| 188 | public function testFilterAndMin(): void |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @return void |
||
| 205 | * @throws \Exception |
||
| 206 | */ |
||
| 207 | public function testFilterAndMax(): void |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @throws \Exception |
||
| 224 | */ |
||
| 225 | public function testFilterWithDateGreaterThanLogic(): void |
||
| 226 | { |
||
| 227 | $this->insertDocumentWithDate(1, new \DateTime('-1 days')); |
||
| 228 | $this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
||
| 229 | |||
| 230 | /** @var ResponseInterface $res */ |
||
| 231 | $row = $this->r()->row('date')->gt((new \DateTime('now'))->format(\DateTime::ATOM)); |
||
| 232 | $cursor = $this->r() |
||
| 233 | ->table('tabletest') |
||
| 234 | ->filter($row) |
||
| 235 | ->run(); |
||
| 236 | |||
| 237 | $this->assertCount(1, $cursor); |
||
|
1 ignored issue
–
show
|
|||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @throws \Exception |
||
| 242 | */ |
||
| 243 | public function testFilterWithDateLowerThanLogic(): void |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @throws \Exception |
||
| 260 | */ |
||
| 261 | public function testFilterWithDateEqualLogic(): void |
||
| 262 | { |
||
| 263 | $this->insertDocumentWithDate(1, $equalDateTime = new \DateTime('-1 days')); |
||
| 264 | $this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
||
| 265 | |||
| 266 | /** @var ResponseInterface $res */ |
||
| 267 | $row = $this->r()->row('date')->eq($equalDateTime->format(\DateTime::ATOM)); |
||
| 268 | $cursor = $this->r() |
||
| 269 | ->table('tabletest') |
||
| 270 | ->filter($row) |
||
| 271 | ->run(); |
||
| 272 | |||
| 273 | $this->assertCount(1, $cursor); |
||
|
1 ignored issue
–
show
|
|||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @throws \Exception |
||
| 278 | */ |
||
| 279 | public function testFilterWithDateNotEqualLogic(): void |
||
| 280 | { |
||
| 281 | $this->insertDocumentWithDate(1, $notEqualDateTime = new \DateTime('-1 days')); |
||
| 282 | $this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
||
| 283 | |||
| 284 | /** @var ResponseInterface $res */ |
||
| 285 | $row = $this->r()->row('date')->ne($notEqualDateTime->format(\DateTime::ATOM)); |
||
| 286 | $cursor = $this->r() |
||
| 287 | ->table('tabletest') |
||
| 288 | ->filter($row) |
||
| 289 | ->run(); |
||
| 290 | |||
| 291 | $this->assertCount(1, $cursor); |
||
|
1 ignored issue
–
show
|
|||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @throws \Exception |
||
| 296 | */ |
||
| 297 | public function testFilterWithDateMultipleLogic(): void |
||
| 317 | } |
||
| 318 | } |
||
| 319 |