Search code examples
phplaravelphpunitlaravel-5.4dingo-api

Internal request does not send parameter when testing


I am using Dingo to manage the API of my application. It has a feature to dispatch an internal request (https://github.com/dingo/api/wiki/Internal-Requests), in the end it calls the Laravel internal request dispatcher.

I am facing the following problem: I make an internal request to a route, it is a POST with parameters. This internal request is called in a queue job. If the this internal request is executed in the queue job it works perfectly, however if in my PHPUnit tests the request is dispatched but the parameters are not sent.

I was debugging and in the controller and $request->input() returns an empty array, but $request->request->all() returns the parameters.

I need $request->input() to return the parameters propertly in all cases.

I am using Laravel 5.4 and Dingo v1.0.0-beta8.

Anyone?


Solution

  • I didn't understand why but if I make a request via Postman the internal request (that is made in the original request) does not use JSON header but if I test it in PHPUnit the JSON header is used. Actually I believe Laravel uses some configuration of the original request.

    The solution was to send the data in header (for non JSON header) and in the content (for JSON header) - in this case must use json_encode in data.