'laravel unit testing get with parameters

I am trying to create a test using get request with parameters

I have a url, say: /api/endpoint/models,

and I want to append parameters, say:

$params = [
    'fields'       => ['id', 'name'],
    'other_fields' => ['desc', 'time']
];

The final url should be: /api/endpoint/model?fields=id&feilds=name&other_fields=desc&other_fields=time

NOTE: the way I receive the params in the controller is by using json_decode($request->fields), json_decode($request->other_fields)

what I did was:

$this->get('/api/endpoint/models?' . http_build_query($params)) 

also tried,

$this->get('/api/endpoint/models?', $filters)

and

$this->call('GET', '/api/endpoint/models?', $filters)

but none seems to work, it always says json_decode(): Argument #1 ($json) must be of type string, array given

I know that I have constructed the URL in a wrong way since it always returns that error, so I came here to know how to construct the URL in a way that it can be received in the controller using json_decode



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source