Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get header values in laravel testing

This is how i get response in test Case

$response = $this->call('POST','/api/auth/login',['username'=>'xx','password'=>'xxx'], [/* cookies */], [/* files */], ['HTTP_ClientSecret' => 'xxxx']);

Then we can get response content by like this

$response->getContents()

i want to know how to get response header data ?

like image 246
yashan Avatar asked Feb 06 '23 16:02

yashan


1 Answers

Do something like:

$response->headers->get('content-type');

or whatever you need. Also dd($response->headers); might be useful to you if you want to see what is in your response headers.

$this->call() returns Response which is extending Symfony's Response and headers is an object ResponseHeaderBag which has the following methods.

like image 153
Ivanka Todorova Avatar answered Feb 10 '23 11:02

Ivanka Todorova