@@ -401,42 +401,39 @@ public function testFailsParsingInvalidRawJsonRequestRaw(): void
401
401
$ body = 'not really{} a json ' ;
402
402
403
403
$ this ->expectException (RequestError::class);
404
- $ this ->expectExceptionMessage ('Could not parse JSON : Syntax error ' );
404
+ $ this ->expectExceptionMessage ('Expected JSON object or array for "application/json" request, but failed to parse because : Syntax error ' );
405
405
$ this ->parseRawRequest ('application/json ' , $ body );
406
406
}
407
407
408
408
public function testFailsParsingInvalidRawJsonRequestPsr (): void
409
409
{
410
410
$ body = 'not really{} a json ' ;
411
411
412
- $ this ->expectException (InvariantViolation ::class);
413
- $ this ->expectExceptionMessage ('Expected to receive a JSON array in body for "application/json" PSR-7 request ' );
412
+ $ this ->expectException (RequestError ::class);
413
+ $ this ->expectExceptionMessage ('Expected JSON object or array for "application/json" request, but failed to parse because: Syntax error ' );
414
414
$ this ->parsePsrRequest ('application/json ' , $ body );
415
415
}
416
416
417
417
public function testFailsParsingNonPreParsedPsrRequest (): void
418
418
{
419
- try {
420
- $ this ->parsePsrRequest ( ' application/json ' , json_encode ( null ) );
421
- self :: fail ( ' Expected exception not thrown ' );
422
- } catch ( InvariantViolation $ e ) {
423
- // Expecting parsing exception to be thrown somewhere else:
424
- self :: assertSame (
425
- ' Expected to receive a JSON array in body for "application/json" PSR-7 request ' ,
426
- $ e -> getMessage ()
427
- );
428
- }
419
+ $ this -> expectException (RequestError::class);
420
+ $ this ->expectExceptionMessage ( ' Expected JSON object or array for " application/json" request, got: null' );
421
+ $ this -> parsePsrRequest ( ' application/json ' , json_encode ( null ) );
422
+ }
423
+
424
+ public function testFailsParsingInvalidEmptyJsonRequestPsr (): void
425
+ {
426
+ $ this -> expectException (RequestError::class);
427
+ $ this -> expectExceptionMessage ( ' Expected JSON object or array for "application/json" request, but failed to parse because: Syntax error ' );
428
+ $ this -> parsePsrRequest ( ' application/json ' , '' );
429
429
}
430
430
431
- /**
432
- * There is no equivalent for psr request, because it should throw
433
- */
434
431
public function testFailsParsingNonArrayOrObjectJsonRequestRaw (): void
435
432
{
436
433
$ body = '"str" ' ;
437
434
438
435
$ this ->expectException (RequestError::class);
439
- $ this ->expectExceptionMessage ('GraphQL Server expects JSON object or array, but got "str" ' );
436
+ $ this ->expectExceptionMessage ('Expected JSON object or array for "application/json" request, got: "str" ' );
440
437
$ this ->parseRawRequest ('application/json ' , $ body );
441
438
}
442
439
@@ -445,7 +442,7 @@ public function testFailsParsingNonArrayOrObjectJsonRequestPsr(): void
445
442
$ body = '"str" ' ;
446
443
447
444
$ this ->expectException (RequestError::class);
448
- $ this ->expectExceptionMessage ('GraphQL Server expects JSON object or array, but got "str" ' );
445
+ $ this ->expectExceptionMessage ('Expected JSON object or array for "application/json" request, got: "str" ' );
449
446
$ this ->parsePsrRequest ('application/json ' , $ body );
450
447
}
451
448
0 commit comments