5
5
use Closure ;
6
6
use Exception ;
7
7
use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
8
+ use Illuminate \Database \Eloquent \Model ;
8
9
use Illuminate \Database \Query \Builder as QueryBuilder ;
9
10
use LastDragon_ru \LaraASP \GraphQL \SearchBy \Contracts \Operator ;
10
11
use LastDragon_ru \LaraASP \GraphQL \SearchBy \Operators \Comparison \Equal ;
@@ -33,6 +34,8 @@ class SearchBuilderTest extends TestCase {
33
34
* @covers ::process
34
35
*
35
36
* @dataProvider dataProviderProcess
37
+ * @dataProvider dataProviderProcessQuery
38
+ * @dataProvider dataProviderProcessEloquent
36
39
*
37
40
* @param array<mixed> $conditions
38
41
*/
@@ -103,6 +106,8 @@ static function (
103
106
* @covers ::processComparison
104
107
*
105
108
* @dataProvider dataProviderProcessComparison
109
+ * @dataProvider dataProviderProcessComparisonQuery
110
+ * @dataProvider dataProviderProcessComparisonEloquent
106
111
*
107
112
* @param array<mixed> $conditions
108
113
*/
@@ -291,9 +296,11 @@ public function dataProviderProcess(): array {
291
296
],
292
297
null ,
293
298
],
294
- 'valid condition ' => [
299
+ 'valid condition with table alias ' => [
295
300
[
296
- 'sql ' => 'select * from "tmp" where (not ((("a" != ?) and ((("a" = ?) or ("b" != ?)))))) ' ,
301
+ 'sql ' => 'select * from "tmp" where ( ' .
302
+ 'not ((("alias"."a" != ?) and ((("alias"."a" = ?) or ("alias"."b" != ?))))) ' .
303
+ ') ' ,
297
304
'bindings ' => [
298
305
1 ,
299
306
2 ,
@@ -326,49 +333,117 @@ public function dataProviderProcess(): array {
326
333
],
327
334
],
328
335
],
329
- null ,
336
+ ' alias ' ,
330
337
],
331
- 'valid condition with table alias ' => [
332
- [
333
- 'sql ' => 'select * from "tmp" where ( ' .
334
- 'not ((("alias"."a" != ?) and ((("alias"."a" = ?) or ("alias"."b" != ?))))) ' .
335
- ') ' ,
336
- 'bindings ' => [
337
- 1 ,
338
- 2 ,
339
- 3 ,
340
- ],
338
+ ]),
339
+ ))->getData ();
340
+ }
341
+
342
+ /**
343
+ * @return array<mixed>
344
+ */
345
+ public function dataProviderProcessQuery (): array {
346
+ return [
347
+ 'query: valid condition ' => [
348
+ [
349
+ 'sql ' => 'select * from "tmp" where ( ' .
350
+ 'not ((("a" != ?) and ((("a" = ?) or ("b" != ?))))) ' .
351
+ ') ' ,
352
+ 'bindings ' => [
353
+ 1 ,
354
+ 2 ,
355
+ 3 ,
341
356
],
342
- [
343
- 'not ' => 'yes ' ,
344
- 'allOf ' => [
345
- [
346
- 'a ' => [
347
- 'eq ' => 1 ,
348
- 'not ' => 'yes ' ,
357
+ ],
358
+ static function (TestCase $ test ): QueryBuilder {
359
+ return $ test ->app ->make ('db ' )->table ('tmp ' );
360
+ },
361
+ [
362
+ 'not ' => 'yes ' ,
363
+ 'allOf ' => [
364
+ [
365
+ 'a ' => [
366
+ 'eq ' => 1 ,
367
+ 'not ' => 'yes ' ,
368
+ ],
369
+ ],
370
+ [
371
+ 'anyOf ' => [
372
+ [
373
+ 'a ' => [
374
+ 'eq ' => 2 ,
375
+ ],
376
+ ],
377
+ [
378
+ 'b ' => [
379
+ 'eq ' => 3 ,
380
+ 'not ' => 'yes ' ,
381
+ ],
349
382
],
350
383
],
351
- [
352
- 'anyOf ' => [
353
- [
354
- 'a ' => [
355
- 'eq ' => 2 ,
356
- ],
384
+ ],
385
+ ],
386
+ ],
387
+ null ,
388
+ ],
389
+ ];
390
+ }
391
+
392
+ /**
393
+ * @return array<mixed>
394
+ */
395
+ public function dataProviderProcessEloquent (): array {
396
+ return [
397
+ 'eloquent: valid condition ' => [
398
+ [
399
+ 'sql ' => 'select * from "tmp" where ( ' .
400
+ 'not ((("tmp"."a" != ?) and ((("tmp"."a" = ?) or ("tmp"."b" != ?))))) ' .
401
+ ') ' ,
402
+ 'bindings ' => [
403
+ 1 ,
404
+ 2 ,
405
+ 3 ,
406
+ ],
407
+ ],
408
+ static function (TestCase $ test ): EloquentBuilder {
409
+ return (new class () extends Model {
410
+ /**
411
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
412
+ *
413
+ * @var string
414
+ */
415
+ public $ table = 'tmp ' ;
416
+ })->query ();
417
+ },
418
+ [
419
+ 'not ' => 'yes ' ,
420
+ 'allOf ' => [
421
+ [
422
+ 'a ' => [
423
+ 'eq ' => 1 ,
424
+ 'not ' => 'yes ' ,
425
+ ],
426
+ ],
427
+ [
428
+ 'anyOf ' => [
429
+ [
430
+ 'a ' => [
431
+ 'eq ' => 2 ,
357
432
],
358
- [
359
- ' b ' => [
360
- ' eq ' => 3 ,
361
- ' not ' => ' yes ' ,
362
- ] ,
433
+ ],
434
+ [
435
+ ' b ' => [
436
+ ' eq ' => 3 ,
437
+ ' not ' => ' yes ' ,
363
438
],
364
439
],
365
440
],
366
441
],
367
442
],
368
- 'alias ' ,
369
443
],
370
- ]),
371
- ))->getData ();
444
+ null ,
445
+ ],
446
+ ];
372
447
}
373
448
374
449
/**
@@ -479,19 +554,6 @@ public function dataProviderProcessComparison(): array {
479
554
],
480
555
null ,
481
556
],
482
- 'valid condition ' => [
483
- [
484
- 'sql ' => 'select * from "tmp" where "property" = ? ' ,
485
- 'bindings ' => [
486
- 123 ,
487
- ],
488
- ],
489
- 'property ' ,
490
- [
491
- 'eq ' => 123 ,
492
- ],
493
- null ,
494
- ],
495
557
'valid condition with table alias ' => [
496
558
[
497
559
'sql ' => 'select * from "tmp" where "alias"."property" = ? ' ,
@@ -508,5 +570,60 @@ public function dataProviderProcessComparison(): array {
508
570
]),
509
571
))->getData ();
510
572
}
573
+
574
+ /**
575
+ * @return array<mixed>
576
+ */
577
+ public function dataProviderProcessComparisonQuery (): array {
578
+ return [
579
+ 'query: valid condition ' => [
580
+ [
581
+ 'sql ' => 'select * from "tmp" where "property" = ? ' ,
582
+ 'bindings ' => [
583
+ 123 ,
584
+ ],
585
+ ],
586
+ static function (TestCase $ test ): QueryBuilder {
587
+ return $ test ->app ->make ('db ' )->table ('tmp ' );
588
+ },
589
+ 'property ' ,
590
+ [
591
+ 'eq ' => 123 ,
592
+ ],
593
+ null ,
594
+ ],
595
+ ];
596
+ }
597
+
598
+ /**
599
+ * @return array<mixed>
600
+ */
601
+ public function dataProviderProcessComparisonEloquent (): array {
602
+ return [
603
+ 'eloquent: valid condition ' => [
604
+ [
605
+ 'sql ' => 'select * from "tmp" where "tmp"."property" = ? ' ,
606
+ 'bindings ' => [
607
+ 123 ,
608
+ ],
609
+ ],
610
+ static function (TestCase $ test ): EloquentBuilder {
611
+ return (new class () extends Model {
612
+ /**
613
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
614
+ *
615
+ * @var string
616
+ */
617
+ public $ table = 'tmp ' ;
618
+ })->query ();
619
+ },
620
+ 'property ' ,
621
+ [
622
+ 'eq ' => 123 ,
623
+ ],
624
+ null ,
625
+ ],
626
+ ];
627
+ }
511
628
// </editor-fold>
512
629
}
0 commit comments