Answer the question
In order to leave comments, you need to log in
How to catch errors when validating an API request using the Argument Resolver?
The guide that was used
Knocks out a huge html canvas with errors
1) App\Tests\UAT\PostControllerTest::createEntity
PHPUnit\Framework\Exception: Symfony\Component\HttpFoundation\Response {#749
+headers: Symfony\Component\HttpFoundation\ResponseHeaderBag {#743
#computedCacheControl: array:2 [
"no-cache" => true
"private" => true
]
#cookies: []
#headerNames: array:5 [
"content-type" => "Content-Type"
"cache-control" => "Cache-Control"
"date" => "Date"
"x-robots-tag" => "X-Robots-Tag"
"allow" => "Allow"
]
#headers: array:5 [
"content-type" => array:1 [
0 => "text/html; charset=UTF-8"
]
"cache-control" => array:1 [
0 => "no-cache, private"
]
"date" => array:1 [
0 => "Wed, 26 Feb 2020 20:17:18 GMT"
]
"x-robots-tag" => array:1 [
0 => "noindex"
]
"allow" => array:1 [
0 => "POST"
]
]
#cacheControl: []
}
#content: """
<!-- Object(App\Entity\Post\DTO\CreatePostRequest).content:\n
This value should not be blank. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)\n
Object(App\Entity\Post\DTO\CreatePostRequest).thumbnailUrl:\n
This value should not be blank. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)\n
(400 Bad Request) -->\n
<!DOCTYPE html>\n
<html lang="en">\n
<head>\n
<meta charset="UTF-8" />\n
....
\n
/*]]>*/ </script>\n
</body>\n
</html>\n
<!-- Object(App\Entity\Post\DTO\CreatePostRequest).content:\n
This value should not be blank. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)\n
Object(App\Entity\Post\DTO\CreatePostRequest).thumbnailUrl:\n
This value should not be blank. (code c1051bb4-d103-4f74-8988-acbcafc7fdc3)\n
(400 Bad Request) -->
"""
#version: "1.1"
#statusCode: 400
#statusText: "Bad Request"
#charset: "UTF-8"
}
Caused by
ErrorException: unserialize(): Error at offset 0 of 150553 bytes in /var/www/event_app_api/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:272
Stack trace:
/**
* @RESTPost("/posts/create")
*
* @param CreatePostRequest $request
* @param ConstraintViolationListInterface $validationErrors
*
* @return JsonResponse
*
*/
public function createAction(
CreatePostRequest $request,
ConstraintViolationListInterface $validationErrors
): JsonResponse
{
dump('VALIDATED');
die;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question