Skip to content

Commit 56bd72c

Browse files
committed
Override test.client service to remove null headers
1 parent c6d5fb5 commit 56bd72c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\BrowserKit;
15+
16+
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
17+
use Symfony\Component\BrowserKit\Request as DomRequest;
18+
use Symfony\Component\HttpFoundation\Request;
19+
20+
class Client extends BaseClient
21+
{
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
protected function filterRequest(DomRequest $request): Request
26+
{
27+
$request = parent::filterRequest($request);
28+
29+
foreach ($request->headers->all() as $key => $value) {
30+
if ([null] === $value) {
31+
$request->headers->remove($key);
32+
}
33+
}
34+
35+
return $request;
36+
}
37+
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ parameters:
8282
container.dumper.inline_class_loader: true
8383

8484
services:
85+
test.client:
86+
class: ApiPlatform\Core\Tests\Fixtures\TestBundle\BrowserKit\Client
87+
shared: false
88+
public: true
89+
arguments:
90+
- '@kernel'
91+
- '%test.client.parameters%'
92+
- '@test.client.history'
93+
- '@test.client.cookiejar'
94+
8595
ApiPlatform\Core\Tests\Fixtures\TestBundle\MessageHandler\:
8696
resource: '../../TestBundle/MessageHandler'
8797
autowire: true

0 commit comments

Comments
 (0)