Symfony functional test - custom headers not passing through
I have the same issue and after a little dig through I think it is a feature that BrowserKit currently doesn't support.
I have logged an issue for it:https://github.com/symfony/symfony/issues/5074
Update: this is not an issue -- see the comments below
Sample Code
Sample request:
$client->request( 'GET', $url, array(), array(), array( 'HTTP_X_CUSTOM_VAR' => $var ));
Fetching the data:
$request->headers->get('x-custom-var');
If you check the definition from Client.php, at method request, you will see in the docblock a very useful information:
- @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
This means that you should add a HTTP_ prefix to the header you want to send. For example if you want to pass header X-HTTP-Method-Override you specify it like so:
$client->request( Request::METHOD_POST, '/api/v1/something', $body, [], ['HTTP_X-HTTP-Method-Override' => Request::METHOD_GET] );