Anyone have any idea on this? I don't believe I am the only one, and a similar (if not the same issue) has been raised when using Lumen too.
May 17, 2017
4
Level 55
phpunit - $this->post fails but $this->json works
I'm implementing an API and writing some tests but I'm running into some issues with the request data (or at least I think so).
- I've added some middleware to validate the headers (Content-Type and Accept)
- The route is POST only
- I validate the request data, one of the items is optional, but when it is present it must be
alpha_dash.
In PHPUnit - When using $this->post(...) I satisfy the other parameters, but intentionally fail the optional one (I provide it but it is malformed) the test fails.
However - When I change the test to use $this->json(...) it works. The reason why I don't want to use $this->json(...) is that I want to verify that my middleware works to validate the headers and by using $this->json(...) it always passes.
From what I've read there are some issues around request data and POST routes but I am unable to find a solution.
Please or to participate in this conversation.