I have an API endpoint which returns bad request response like this:
{
"code": 400,
"message": "Entity App\\Entity\\Seller can not be found"
}
It is generated by using fos_rest.request_body ParamConverter.
Now the problem is that if I run this endpoint on my PHPUnit test case - it always returns 500 Internal Server Error. While the response with code 400 always comes back using regular browser or Postman app.
Any ideas how to make that response as it is on PHPUnit side? It should be 400 so I could assert it.
Also if I set the client catchExceptions parameter to false, then it shows the real error which is:
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Entity App\Entity\Seller can not be found /var/www/pmp-api/vendor/friendsofsymfony/rest-bundle/Request/RequestBodyParamConverter.php:94
Is it possible to catch the 400 response somehow or I will have to use try catch inside my testcase?
I have an API endpoint which returns bad request response like this:
It is generated by using fos_rest.request_body ParamConverter.
Now the problem is that if I run this endpoint on my PHPUnit test case - it always returns 500 Internal Server Error. While the response with code 400 always comes back using regular browser or Postman app.
Any ideas how to make that response as it is on PHPUnit side? It should be 400 so I could assert it.
Application test client is created from this class: https://github.com/symfony/symfony/blob/6.0/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
Also if I set the client catchExceptions parameter to false, then it shows the real error which is:
Symfony\Component\HttpKernel\Exception\BadRequestHttpException: Entity App\Entity\Seller can not be found /var/www/pmp-api/vendor/friendsofsymfony/rest-bundle/Request/RequestBodyParamConverter.php:94
Is it possible to catch the 400 response somehow or I will have to use try catch inside my testcase?