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