I am writing an integration test in Symfony with a request that includes custom headers. However, the request fails because the custom header is apparently missing.
What happened was I forgot to add an HTTP prefix to the custom header.
This is a common pitfall when writing integration tests in Symfony and using custom HTTP headers: the necessity to add an HTTP_ prefix to the header in the test.
If you do not add the prefix to the custom header, it will silently not be added to the request, and you have to debug why the request fails.
So this will fail:
static::$client->request('GET', '/ping', [], [], ['X-Custom-Header' => 'custom']);
Code language: PHP (php)
And this will work:
static::$client->request('GET', '/ping', [], [], ['HTTP_X-Custom-Header' => 'custom']);
Code language: PHP (php)
Continue reading “Symfony integration tests custom header is missing”