@@ -332,4 +332,119 @@ public function testFiltersCustom() {
332
332
);
333
333
});
334
334
}
335
+
336
+
337
+ /**
338
+ * Test filters : typed filter
339
+ */
340
+ public function testTypedFilter () {
341
+ factory (Entity \User::class)->create (['name ' => 'foo ' ]);
342
+ factory (Entity \User::class)->create (['name ' => 'bar ' ]);
343
+ factory (Entity \User::class)->create (['name ' => 'baz ' ]);
344
+ factory (Entity \User::class)->create (['name ' => 'foobar ' ]);
345
+
346
+ $ this ->registerAllDefinitions ();
347
+
348
+ $ this ->specify ('test equality custom ' , function () {
349
+ // We should only get users which name starts with 'ba'
350
+ $ query = <<<'EOGQL'
351
+ query ($filter: UserFilter) {
352
+ users(filter: $filter) {
353
+ items {
354
+ name
355
+ }
356
+ }
357
+ }
358
+ EOGQL;
359
+
360
+ $ res = $ this ->executeGraphQL ($ query , [
361
+ 'variables ' => [
362
+ 'filter ' => [
363
+ 'nameLikeViaTypedFilter ' => 'ba '
364
+ ]
365
+ ]
366
+ ]);
367
+
368
+ $ this ->assertSame (
369
+ ['bar ' ,'baz ' ,'foobar ' ],
370
+ array_column ($ res ['data ' ]['users ' ]['items ' ], 'name ' )
371
+ );
372
+ });
373
+ }
374
+
375
+ /**
376
+ * Test filters : closure filter as array
377
+ */
378
+ public function testFilterAsArrayClosure () {
379
+ factory (Entity \User::class)->create (['name ' => 'foo ' ]);
380
+ factory (Entity \User::class)->create (['name ' => 'bar ' ]);
381
+ factory (Entity \User::class)->create (['name ' => 'baz ' ]);
382
+ factory (Entity \User::class)->create (['name ' => 'foobar ' ]);
383
+
384
+ $ this ->registerAllDefinitions ();
385
+
386
+ $ this ->specify ('test equality custom ' , function () {
387
+ // We should only get users which name starts with 'ba'
388
+ $ query = <<<'EOGQL'
389
+ query ($filter: UserFilter) {
390
+ users(filter: $filter) {
391
+ items {
392
+ name
393
+ }
394
+ }
395
+ }
396
+ EOGQL;
397
+
398
+ $ res = $ this ->executeGraphQL ($ query , [
399
+ 'variables ' => [
400
+ 'filter ' => [
401
+ 'nameLikeArrayClosure ' => 'ba% '
402
+ ]
403
+ ]
404
+ ]);
405
+
406
+ $ this ->assertSame (
407
+ ['bar ' ,'baz ' ],
408
+ array_column ($ res ['data ' ]['users ' ]['items ' ], 'name ' )
409
+ );
410
+ });
411
+ }
412
+
413
+ /**
414
+ * Test filters : typed filter as array
415
+ */
416
+ public function testFilterAsArrayTypedFilter () {
417
+ factory (Entity \User::class)->create (['name ' => 'foo ' ]);
418
+ factory (Entity \User::class)->create (['name ' => 'bar ' ]);
419
+ factory (Entity \User::class)->create (['name ' => 'baz ' ]);
420
+ factory (Entity \User::class)->create (['name ' => 'foobar ' ]);
421
+
422
+ $ this ->registerAllDefinitions ();
423
+
424
+ $ this ->specify ('test equality custom ' , function () {
425
+ // We should only get users which name starts with 'ba'
426
+ $ query = <<<'EOGQL'
427
+ query ($filter: UserFilter) {
428
+ users(filter: $filter) {
429
+ items {
430
+ name
431
+ }
432
+ }
433
+ }
434
+ EOGQL;
435
+
436
+ $ res = $ this ->executeGraphQL ($ query , [
437
+ 'variables ' => [
438
+ 'filter ' => [
439
+ 'nameLikeArrayTypedFilter ' => 'ba '
440
+ ]
441
+ ]
442
+ ]);
443
+
444
+ $ this ->assertSame (
445
+ ['bar ' ,'baz ' ,'foobar ' ],
446
+ array_column ($ res ['data ' ]['users ' ]['items ' ], 'name ' )
447
+ );
448
+ });
449
+ }
335
450
}
0 commit comments