@@ -184,10 +184,19 @@ public function testGetAllRecordsWithEqualCondition()
184
184
$ this ->seed (['count ' => ['N ' => 10 ]]);
185
185
$ this ->seed (['count ' => ['N ' => 10 ]]);
186
186
$ this ->seed (['count ' => ['N ' => 10 ]]);
187
+ $ this ->seed (['count ' => ['N ' => 9 ]]);
188
+
189
+ $ items = $ this ->testModel ->where ('count ' , 10 )->get ();
190
+
191
+ $ this ->assertEquals (3 , $ items ->count ());
187
192
188
- $ items = $ this ->testModel ->where ('count ' , 10 )->get ()->toArray ();
193
+ // OR condition
194
+ $ items = $ this ->testModel
195
+ ->where ('count ' , 10 )
196
+ ->orWhere ('count ' , 9 )
197
+ ->get ();
189
198
190
- $ this ->assertEquals (3 , count ( $ items ));
199
+ $ this ->assertEquals (4 , $ items-> count ( ));
191
200
}
192
201
193
202
public function testGetAllRecordsWithNonEqualCondition ()
@@ -196,9 +205,17 @@ public function testGetAllRecordsWithNonEqualCondition()
196
205
$ this ->seed (['count ' => ['N ' => 11 ]]);
197
206
$ this ->seed (['count ' => ['N ' => 11 ]]);
198
207
199
- $ items = $ this ->testModel ->where ('count ' , '!= ' , 10 )->get ()-> toArray () ;
208
+ $ items = $ this ->testModel ->where ('count ' , '!= ' , 10 )->get ();
200
209
201
- $ this ->assertEquals (2 , count ($ items ));
210
+ $ this ->assertEquals (2 , $ items ->count ());
211
+
212
+ // OR condition
213
+ $ items = $ this ->testModel
214
+ ->where ('count ' , '!= ' , 10 )
215
+ ->orWhere ('count ' , '!= ' , 11 )
216
+ ->get ();
217
+
218
+ $ this ->assertEquals (3 , $ items ->count ());
202
219
}
203
220
204
221
public function testGetAllRecordsWithGTCondition ()
@@ -207,9 +224,17 @@ public function testGetAllRecordsWithGTCondition()
207
224
$ this ->seed (['count ' => ['N ' => 11 ]]);
208
225
$ this ->seed (['count ' => ['N ' => 11 ]]);
209
226
210
- $ items = $ this ->testModel ->where ('count ' , '> ' , 10 )->get ()-> toArray () ;
227
+ $ items = $ this ->testModel ->where ('count ' , '> ' , 10 )->get ();
211
228
212
- $ this ->assertEquals (2 , count ($ items ));
229
+ $ this ->assertEquals (2 , $ items ->count ());
230
+
231
+ // OR condition
232
+ $ items = $ this ->testModel
233
+ ->where ('count ' , '> ' , 100 )
234
+ ->orWhere ('count ' , '> ' , 10 )
235
+ ->get ();
236
+
237
+ $ this ->assertEquals (2 , $ items ->count ());
213
238
}
214
239
215
240
public function testGetAllRecordsWithLTCondition ()
@@ -218,9 +243,17 @@ public function testGetAllRecordsWithLTCondition()
218
243
$ this ->seed (['count ' => ['N ' => 9 ]]);
219
244
$ this ->seed (['count ' => ['N ' => 11 ]]);
220
245
221
- $ items = $ this ->testModel ->where ('count ' , '< ' , 10 )->get ()-> toArray () ;
246
+ $ items = $ this ->testModel ->where ('count ' , '< ' , 10 )->get ();
222
247
223
- $ this ->assertEquals (1 , count ($ items ));
248
+ $ this ->assertEquals (1 , $ items ->count ());
249
+
250
+ // OR condition
251
+ $ items = $ this ->testModel
252
+ ->where ('count ' , '< ' , 1 )
253
+ ->orWhere ('count ' , '< ' , 10 )
254
+ ->get ();
255
+
256
+ $ this ->assertEquals (1 , $ items ->count ());
224
257
}
225
258
226
259
public function testGetAllRecordsWithGECondition ()
@@ -229,9 +262,17 @@ public function testGetAllRecordsWithGECondition()
229
262
$ this ->seed (['count ' => ['N ' => 9 ]]);
230
263
$ this ->seed (['count ' => ['N ' => 11 ]]);
231
264
232
- $ items = $ this ->testModel ->where ('count ' , '>= ' , 10 )->get ()-> toArray () ;
265
+ $ items = $ this ->testModel ->where ('count ' , '>= ' , 10 )->get ();
233
266
234
- $ this ->assertEquals (2 , count ($ items ));
267
+ $ this ->assertEquals (2 , $ items ->count ());
268
+
269
+ // OR condition
270
+ $ items = $ this ->testModel
271
+ ->where ('count ' , '>= ' , 10 )
272
+ ->orWhere ('count ' , '>= ' , 100 )
273
+ ->get ();
274
+
275
+ $ this ->assertEquals (2 , $ items ->count ());
235
276
}
236
277
237
278
public function testGetAllRecordsWithLECondition ()
@@ -240,9 +281,17 @@ public function testGetAllRecordsWithLECondition()
240
281
$ this ->seed (['count ' => ['N ' => 9 ]]);
241
282
$ this ->seed (['count ' => ['N ' => 11 ]]);
242
283
243
- $ items = $ this ->testModel ->where ('count ' , '<= ' , 10 )->get ()-> toArray () ;
284
+ $ items = $ this ->testModel ->where ('count ' , '<= ' , 10 )->get ();
244
285
245
- $ this ->assertEquals (2 , count ($ items ));
286
+ $ this ->assertEquals (2 , $ items ->count ());
287
+
288
+ // OR condition
289
+ $ items = $ this ->testModel
290
+ ->where ('count ' , '<= ' , 10 )
291
+ ->orWhere ('count ' , '<= ' , 1 )
292
+ ->get ();
293
+
294
+ $ this ->assertEquals (2 , $ items ->count ());
246
295
}
247
296
248
297
public function testGetAllRecordsWithBeginsWithOperator ()
@@ -251,51 +300,83 @@ public function testGetAllRecordsWithBeginsWithOperator()
251
300
$ this ->seed (['description ' => ['S ' => 'Foo_2 ' ]]);
252
301
$ this ->seed (['description ' => ['S ' => 'Bar_Foo ' ]]);
253
302
254
- $ items = $ this ->testModel ->where ('description ' , 'BEGINS_WITH ' , 'Foo ' )->get ()-> toArray () ;
303
+ $ items = $ this ->testModel ->where ('description ' , 'BEGINS_WITH ' , 'Foo ' )->get ();
255
304
256
- $ this ->assertEquals (2 , count ($ items ));
305
+ $ this ->assertEquals (2 , $ items ->count ());
306
+
307
+ // OR condition
308
+ $ items = $ this ->testModel
309
+ ->where ('description ' , 'BEGINS_WITH ' , 'Foo ' )
310
+ ->orWhere ('description ' , 'BEGINS_WITH ' , 'Bar ' )
311
+ ->get ();
312
+
313
+ $ this ->assertEquals (3 , $ items ->count ());
257
314
}
258
315
259
316
public function testGetAllRecordsWithContainsOperator ()
260
317
{
261
318
$ this ->seed (['description ' => ['L ' => [['S ' => 'foo ' ], ['S ' => 'bar ' ]]]]);
262
319
$ this ->seed (['description ' => ['L ' => [['S ' => 'foo ' ], ['S ' => 'bar2 ' ]]]]);
263
320
264
- $ items = $ this ->testModel ->where ('description ' , 'CONTAINS ' , 'foo ' )->get ()-> toArray () ;
321
+ $ items = $ this ->testModel ->where ('description ' , 'CONTAINS ' , 'foo ' )->get ();
265
322
266
- $ this ->assertEquals (2 , count ( $ items ));
323
+ $ this ->assertEquals (2 , $ items-> count ( ));
267
324
268
- $ items = $ this ->testModel ->where ('description ' , 'CONTAINS ' , 'bar2 ' )->get ()->toArray ();
325
+ $ items = $ this ->testModel ->where ('description ' , 'CONTAINS ' , 'bar2 ' )->get ();
326
+
327
+ $ this ->assertEquals (1 , $ items ->count ());
328
+
329
+ // OR condition
330
+ $ items = $ this ->testModel
331
+ ->where ('description ' , 'CONTAINS ' , 'bar2 ' )
332
+ ->orWhere ('description ' , 'CONTAINS ' , 'foo ' )
333
+ ->get ();
269
334
270
- $ this ->assertEquals (1 , count ( $ items ));
335
+ $ this ->assertEquals (2 , $ items-> count ( ));
271
336
}
272
337
273
338
public function testGetAllRecordsWithNotContainsOperator ()
274
339
{
275
340
$ this ->seed (['description ' => ['L ' => [['S ' => 'foo ' ], ['S ' => 'bar ' ]]]]);
276
341
$ this ->seed (['description ' => ['L ' => [['S ' => 'foo ' ], ['S ' => 'bar2 ' ]]]]);
277
342
278
- $ items = $ this ->testModel ->where ('description ' , 'NOT_CONTAINS ' , 'foo ' )->get ()-> toArray () ;
343
+ $ items = $ this ->testModel ->where ('description ' , 'NOT_CONTAINS ' , 'foo ' )->get ();
279
344
280
- $ this ->assertEquals (0 , count ( $ items ));
345
+ $ this ->assertEquals (0 , $ items-> count ( ));
281
346
282
- $ items = $ this ->testModel ->where ('description ' , 'NOT_CONTAINS ' , 'foobar ' )->get ()-> toArray () ;
347
+ $ items = $ this ->testModel ->where ('description ' , 'NOT_CONTAINS ' , 'foobar ' )->get ();
283
348
284
- $ this ->assertEquals (2 , count ($ items ));
349
+ $ this ->assertEquals (2 , $ items ->count ());
350
+
351
+ // OR condition
352
+ $ items = $ this ->testModel
353
+ ->where ('description ' , 'NOT_CONTAINS ' , 'oo ' )
354
+ ->orWhere ('description ' , 'NOT_CONTAINS ' , 'aa ' )
355
+ ->get ();
356
+
357
+ $ this ->assertEquals (2 , $ items ->count ());
285
358
}
286
359
287
360
public function testGetAllRecordsWithBetweenOperator ()
288
361
{
289
362
$ this ->seed (['description ' => ['N ' => 10 ]]);
290
363
$ this ->seed (['description ' => ['N ' => 11 ]]);
291
364
292
- $ items = $ this ->testModel ->where ('description ' , 'BETWEEN ' , [1 , 11 ])->get ()-> toArray () ;
365
+ $ items = $ this ->testModel ->where ('description ' , 'BETWEEN ' , [1 , 11 ])->get ();
293
366
294
- $ this ->assertEquals (2 , count ($ items ));
367
+ $ this ->assertEquals (2 , $ items ->count ());
368
+
369
+ $ items = $ this ->testModel ->where ('description ' , 'BETWEEN ' , [100 , 110 ])->get ();
370
+
371
+ $ this ->assertEquals (0 , $ items ->count ());
295
372
296
- $ items = $ this ->testModel ->where ('description ' , 'BETWEEN ' , [100 , 110 ])->get ()->toArray ();
373
+ // OR condition
374
+ $ items = $ this ->testModel
375
+ ->where ('description ' , 'BETWEEN ' , [100 , 110 ])
376
+ ->orWhere ('description ' , 'BETWEEN ' , [1 , 11 ])
377
+ ->get ();
297
378
298
- $ this ->assertEquals (0 , count ( $ items ));
379
+ $ this ->assertEquals (2 , $ items-> count ( ));
299
380
}
300
381
301
382
public function testGetFirstRecord ()
@@ -394,6 +475,18 @@ public function testWhereIn()
394
475
foreach ($ items as $ item ) {
395
476
$ this ->assertContains ($ item ->name , ['foo ' , 'bar ' ]);
396
477
}
478
+
479
+ // OR condition
480
+ $ items = $ this ->testModel
481
+ ->whereIn ('name ' , ['foo ' , 'bar ' ])
482
+ ->orWhereIn ('name ' , ['foobar ' ])
483
+ ->get ();
484
+
485
+ $ this ->assertEquals (4 , $ items ->count ());
486
+
487
+ foreach ($ items as $ item ) {
488
+ $ this ->assertContains ($ item ->name , ['foo ' , 'bar ' , 'foobar ' ]);
489
+ }
397
490
}
398
491
399
492
public function testWhereNull ()
@@ -406,6 +499,13 @@ public function testWhereNull()
406
499
$ this ->assertEquals (1 , $ items ->count ());
407
500
408
501
$ this ->assertNull ($ items ->first ()->name );
502
+
503
+ // OR condition
504
+ $ items = $ this ->testModel ->whereNull ('name ' )->orWhereNull ('description ' )->get ();
505
+
506
+ $ this ->assertEquals (1 , $ items ->count ());
507
+
508
+ $ this ->assertNull ($ items ->first ()->name );
409
509
}
410
510
411
511
public function testWhereNotNull ()
@@ -418,6 +518,11 @@ public function testWhereNotNull()
418
518
$ this ->assertEquals (1 , $ items ->count ());
419
519
420
520
$ this ->assertNotNull ($ items ->first ()->name );
521
+
522
+ // OR condition
523
+ $ items = $ this ->testModel ->whereNotNull ('name ' )->orWhereNotNull ('description ' )->get ();
524
+
525
+ $ this ->assertEquals (2 , $ items ->count ());
421
526
}
422
527
423
528
public function testChunkScan ()
0 commit comments