Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel unit testing a route with a query string

$response = $this->call('GET','abc?foo=bar');

I'm unable to get PHPUnit to transmit foo as a request variable. Any thoughts? Am I missing something?

like image 485
Bradley Avatar asked Jun 01 '26 19:06

Bradley


1 Answers

Your issue is not a PHPUnit issue, it is a Laravel one.

The call() method has the following signature:

call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null);

You should send the query string as an associative array.

If you want to directly test a controller, you should use the action() method, which has the following signature:

action($method, $action, $wildcards = [], $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
like image 193
Dov Benyomin Sohacheski Avatar answered Jun 03 '26 08:06

Dov Benyomin Sohacheski