Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding test.client.parameters for HTTP_HOST does not work with WebTestCase #12189

Closed
adrienbrault opened this issue Oct 9, 2014 · 5 comments

Comments

@adrienbrault
Copy link
Contributor

Hi,

I've tried to override the test client HTTP_HOST server param in my app config:

parameters:
    test.client.parameters:
        HTTP_HOST: symfony.com

However, in functional tests (WebTestCase), $client->getServerParameter('HTTP_HOST') does not return symfony.com but the default localhost.

The client is actually correctly configured at

$client = static::$kernel->getContainer()->get('test.client');

but the call on the next line $client->setServerParameters($server); with an empty array erases HTTP_HOST because of the method definition:

public function setServerParameters(array $server)
{
$this->server = array_merge(array(
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
), $server);
}

@stayeronglass
Copy link

any progress?

@jakzal
Copy link
Contributor

jakzal commented Mar 21, 2016

should be fixed by #16265

@jakzal jakzal closed this as completed Mar 21, 2016
@aistis-
Copy link

aistis- commented Nov 16, 2016

Does anyone face the same problem with other parameters?

# config_test.yml
...
parameters:
    test.client.parameters:
        HTTPS: true

@MacDada
Copy link
Contributor

MacDada commented Sep 28, 2020

That's still an issue when using a default WebTestCase:

# services_test.yml
parameters:
    test.client.parameters:
        HTTP_HOST: 'example.dev'

The config works and in the Client constructor the host is being configured: https://github.com/symfony/symfony/blob/v3.4.45/src/Symfony/Component/BrowserKit/Client.php#L55

BUT, WebTestCase overrides it: https://github.com/symfony/symfony/blob/v3.4.45/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php#L45

And that forces me to override WebTestCase and set proper host manually instead of depending on config.


Possible solution: #20535 – it was a good one – overriding just the parameters that are needed, not all of them.

There was a concern about BC, but it can be handled: #20535 (comment)

I can make a new PR if this is acceptable solution.

@MacDada
Copy link
Contributor

MacDada commented Sep 28, 2020

Where should I add test for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants