While doing a request through curl or postman, extended Request (extending Illuminate Request) content is dynamically loaded in $request->getContent() method from the input stream. But in case of test case, its empty string. So, no content is loaded and request validation fails.
Illuminate\Http\Requestname as request content field$this->json('GET', '/route', ['name' => 'test']);name is passed as content)I have faced the same issue. Looks like framework design problem.
@apaarmann Have you solved this?
Having same issue. curl call returns proper JSON response but API call returns info in the public $original as a class object and the public $content is '{}'
Main difference in the testing is the API call pulls from Eloquent DB entry and phptest pulls from Temporary Memory entries.
same problem with me
here is my test functions body
public function testLogin()
{
$this->json('POST', 'v1/auth/login', [
'login' => 'moeen-basra',
'password' => 'secret',
])
->seeStatusCode(200)
->seeJson(['token' => '*']);
}
in controller when I try to access $request->all(); is empty.
Has anyone found a workaround for this?
My problem was I was using the magic $_GET to retrieve params in the controller. Changing to request->all() solved this.
class MyGetController extends Controller
{
public function myGetControllerFunction(Request $request)
{
//$my_params = $_GET; // doesn't work with unit-test
$my_params = $request->all(); //this works
...
For anyone else that stumbles upon this... I found this in the Lumen docs:
Form requests are not supported by Lumen. If you would like to use form requests, you should use the full Laravel framework.
I was attempting to use a subclass of Request to handle authorization and validation, but apparently that doesn't work in lumen. Instead, it looks like they expect that to be in the controller using $this->validate() and $this->authorize().
Form requests are indeed not supported in Lumen. You should use the Validator class directly in your controller.
Most helpful comment
same problem with me
here is my test functions body
in controller when I try to access $request->all(); is empty.