Xairo Martínez Xairo Martínez - 5 months ago 39
PHP Question

Laravel 5.2 unit test set headers not working

I have the following assert:

$this->call('GET', '/api/v1/ubication/suggest', [
'term' => 'a'
], [], [], ['Accept' => 'application/json']);


The call method definition is as follow:

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


I'm passing my header in the $server position but i still get 302 status code in the response(I'm testing a Request validation) instead of 422 that is what i expect.

How can i simulate that header in the test?


If you want to make a GET call with Headers, you can use:

$this->get($url, $headers);


$this->get('/oauth', [ 'HTTP_X_API_KEY' => 'xxxx' ]);

Since you are making a GET request, your parameters can be included in the $url.