@@ -401,6 +401,109 @@ public function testAssertWhereFailsWhenDoesNotMatchValueUsingArrayable()
401
401
]);
402
402
}
403
403
404
+ public function testAssertWhereHasFailsWithEmptyValue ()
405
+ {
406
+ $ assert = AssertableJson::fromArray ([]);
407
+
408
+ $ this ->expectException (AssertionFailedError::class);
409
+ $ this ->expectExceptionMessage ('Property [foo] does not contain [1]. ' );
410
+
411
+ $ assert ->whereHas ('foo ' , ['1 ' ]);
412
+ }
413
+
414
+ public function testAssertWhereHasFailsWithMissingValue ()
415
+ {
416
+ $ assert = AssertableJson::fromArray ([
417
+ 'foo ' => ['bar ' , 'baz ' ],
418
+ ]);
419
+
420
+ $ this ->expectException (AssertionFailedError::class);
421
+ $ this ->expectExceptionMessage ('Property [foo] does not contain [invalid]. ' );
422
+
423
+ $ assert ->whereHas ('foo ' , ['bar ' , 'baz ' , 'invalid ' ]);
424
+ }
425
+
426
+ public function testAssertWhereHasFailsWithMissingNestedValue ()
427
+ {
428
+ $ assert = AssertableJson::fromArray ([
429
+ ['id ' => 1 ],
430
+ ['id ' => 2 ],
431
+ ['id ' => 3 ],
432
+ ['id ' => 4 ],
433
+ ]);
434
+
435
+ $ this ->expectException (AssertionFailedError::class);
436
+ $ this ->expectExceptionMessage ('Property [id] does not contain [5]. ' );
437
+
438
+ $ assert ->whereHas ('id ' , [1 ,2 ,3 ,4 ,5 ]);
439
+ }
440
+
441
+ public function testAssertWhereHasFailsWhenDoesNotMatchType ()
442
+ {
443
+ $ assert = AssertableJson::fromArray ([
444
+ 'foo ' => [1 ,2 ,3 ,4 ]
445
+ ]);
446
+
447
+ $ this ->expectException (AssertionFailedError::class);
448
+ $ this ->expectExceptionMessage ('Property [foo] does not contain [1]. ' );
449
+
450
+ $ assert ->whereHas ('foo ' , ['1 ' ]);
451
+ }
452
+
453
+ public function testAssertWhereHasWithNestedValue ()
454
+ {
455
+ $ assert = AssertableJson::fromArray ([
456
+ ['id ' => 1 ],
457
+ ['id ' => 2 ],
458
+ ['id ' => 3 ],
459
+ ['id ' => 4 ],
460
+ ]);
461
+
462
+ $ assert ->whereHas ('id ' , 1 );
463
+ $ assert ->whereHas ('id ' , [1 ,2 ,3 ,4 ]);
464
+ $ assert ->whereHas ('id ' , [4 ,3 ,2 ,1 ]);
465
+ }
466
+
467
+ public function testAssertWhereHasWithMatchingType ()
468
+ {
469
+ $ assert = AssertableJson::fromArray ([
470
+ 'foo ' => [1 ,2 ,3 ,4 ]
471
+ ]);
472
+
473
+ $ assert ->whereHas ('foo ' , 1 );
474
+ $ assert ->whereHas ('foo ' , [1 ]);
475
+ }
476
+
477
+ public function testAssertWhereHasWithNullValue ()
478
+ {
479
+ $ assert = AssertableJson::fromArray ([
480
+ 'foo ' => null ,
481
+ ]);
482
+
483
+ $ assert ->whereHas ('foo ' , null );
484
+ $ assert ->whereHas ('foo ' , [null ]);
485
+ }
486
+
487
+ public function testAssertWhereHasWithOutOfOrderMatchingType ()
488
+ {
489
+ $ assert = AssertableJson::fromArray ([
490
+ 'foo ' => [4 ,1 ,7 ,3 ]
491
+ ]);
492
+
493
+ $ assert ->whereHas ('foo ' , [1 ,7 ,4 ,3 ]);
494
+ }
495
+
496
+ public function testAssertWhereHasWithOutOfOrderNestedMatchingType ()
497
+ {
498
+ $ assert = AssertableJson::fromArray ([
499
+ ['bar ' => 5 ],
500
+ ['baz ' => 4 ],
501
+ ['zal ' => 8 ],
502
+ ]);
503
+
504
+ $ assert ->whereHas ('baz ' , 4 );
505
+ }
506
+
404
507
public function testAssertNestedWhereMatchesValue ()
405
508
{
406
509
$ assert = AssertableJson::fromArray ([
0 commit comments