@@ -355,6 +355,124 @@ public function testAssertJsonValidationErrorsFailsWhenGivenAnEmptyArray()
355355 $ testResponse ->assertJsonValidationErrors ([]);
356356 }
357357
358+ public function testAssertJsonValidationErrorsWithArray ()
359+ {
360+ $ data = [
361+ 'status ' => 'ok ' ,
362+ 'errors ' => ['foo ' => 'one ' , 'bar ' => 'two ' ],
363+ ];
364+
365+ $ testResponse = TestResponse::fromBaseResponse (
366+ (new Response )->setContent (json_encode ($ data ))
367+ );
368+
369+ $ testResponse ->assertJsonValidationErrors (['foo ' , 'bar ' ]);
370+ }
371+
372+ public function testAssertJsonValidationErrorMessages ()
373+ {
374+ $ data = [
375+ 'status ' => 'ok ' ,
376+ 'errors ' => ['key ' => 'foo ' ],
377+ ];
378+
379+ $ testResponse = TestResponse::fromBaseResponse (
380+ (new Response )->setContent (json_encode ($ data ))
381+ );
382+
383+ $ testResponse ->assertJsonValidationErrors (['key ' => 'foo ' ]);
384+ }
385+
386+ public function testAssertJsonValidationErrorContainsMessages ()
387+ {
388+ $ data = [
389+ 'status ' => 'ok ' ,
390+ 'errors ' => ['key ' => 'foo bar ' ],
391+ ];
392+
393+ $ testResponse = TestResponse::fromBaseResponse (
394+ (new Response )->setContent (json_encode ($ data ))
395+ );
396+
397+ $ testResponse ->assertJsonValidationErrors (['key ' => 'foo ' ]);
398+ }
399+
400+ public function testAssertJsonValidationErrorMessagesCanFail ()
401+ {
402+ $ this ->expectException (AssertionFailedError::class);
403+
404+ $ data = [
405+ 'status ' => 'ok ' ,
406+ 'errors ' => ['key ' => 'foo ' ],
407+ ];
408+
409+ $ testResponse = TestResponse::fromBaseResponse (
410+ (new Response )->setContent (json_encode ($ data ))
411+ );
412+
413+ $ testResponse ->assertJsonValidationErrors (['key ' => 'bar ' ]);
414+ }
415+
416+ public function testAssertJsonValidationErrorMessageKeyCanFail ()
417+ {
418+ $ this ->expectException (AssertionFailedError::class);
419+
420+ $ data = [
421+ 'status ' => 'ok ' ,
422+ 'errors ' => ['foo ' => 'value ' ],
423+ ];
424+
425+ $ testResponse = TestResponse::fromBaseResponse (
426+ (new Response )->setContent (json_encode ($ data ))
427+ );
428+
429+ $ testResponse ->assertJsonValidationErrors (['bar ' => 'value ' ]);
430+ }
431+
432+ public function testAssertJsonValidationErrorMessagesMultipleMessages ()
433+ {
434+ $ data = [
435+ 'status ' => 'ok ' ,
436+ 'errors ' => ['one ' => 'foo ' , 'two ' => 'bar ' ],
437+ ];
438+
439+ $ testResponse = TestResponse::fromBaseResponse (
440+ (new Response )->setContent (json_encode ($ data ))
441+ );
442+
443+ $ testResponse ->assertJsonValidationErrors (['one ' => 'foo ' , 'two ' => 'bar ' ]);
444+ }
445+
446+ public function testAssertJsonValidationErrorMessagesMixed ()
447+ {
448+ $ data = [
449+ 'status ' => 'ok ' ,
450+ 'errors ' => ['one ' => 'foo ' , 'two ' => 'bar ' ],
451+ ];
452+
453+ $ testResponse = TestResponse::fromBaseResponse (
454+ (new Response )->setContent (json_encode ($ data ))
455+ );
456+
457+ $ testResponse ->assertJsonValidationErrors (['one ' => 'foo ' , 'two ' ]);
458+ }
459+
460+ public function testAssertJsonValidationErrorMessagesMixedCanFail ()
461+ {
462+ $ this ->expectException (AssertionFailedError::class);
463+
464+ $ data = [
465+ 'status ' => 'ok ' ,
466+ 'errors ' => ['one ' => 'foo ' , 'two ' => 'bar ' ],
467+ ];
468+
469+ $ testResponse = TestResponse::fromBaseResponse (
470+ (new Response )->setContent (json_encode ($ data ))
471+ );
472+
473+ $ testResponse ->assertJsonValidationErrors (['one ' => 'taylor ' , 'otwell ' ]);
474+ }
475+
358476 public function testAssertJsonMissingValidationErrors ()
359477 {
360478 $ baseResponse = tap (new Response , function ($ response ) {
0 commit comments