-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
BrowserKit\Client::request() overwrites $server values #18771
Comments
|
Yes, it was definitely a hack, you found me guilty ;-) (and this is actually not the first one I tried). Usually, when I have to work with CLI and router, I use the Is there a good way to call Thank you. |
I think I'm wrong since the beginning. My Apache server is currently down, but I can still run my tests (and it works now !). So what I was missing since the beginning is that the way phpunit runs the tests and the way Apache is configured are two separate things with no interaction between them. I was wrong to try to force usage of my Apache alias. Now I have something like that (and the simplicity talks for itself) : $client = static::createClient() ;
$client->followRedirects ;
$crawler = $client->request(GET, '/myroute') ; I guess phpunit uses the built-in server, but I have found no clue of that. The only thing I can't do is to use Anyway, there is no bug here. |
Phpunit does not use the built-in server. Web test cases are not run in a context of a web server at all. Instead, Symfony kernel is created and called directly (there's no http request). |
Thank you for your reply. |
I am running some tests with phpunit. My Apache server is configured to use an alias, so to create my client I set the parameter HTTP_HOST like this :
Then, I do a request with absolute URL and no
$server
parameter :request()
method is called, everything is fine. But there is a redirection, and in header the Location is set to/myalias/app_dev.php/myotherroute
, URL is no more absolute (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/BrowserKit/Client.php#L325).followRedirects
set totrue
, therequest()
method is called a second time. But this time, the parameter$server
is not empty as it was the first time, but it has a keyHTTP_HOST
set to null.$server
is merged with$this->server
(here : https://github.com/symfony/symfony/blob/master/src/Symfony/Component/BrowserKit/Client.php#L288), the previousHTTP_HOST
I defined withcreateClient()
becomes null too.extractHost()
As a consequence, I am doing a
GET /myalias/app_dev.php/myotherroute
on localhost, which returns 404.I hope my explanations are not too confused... Any idea if I can fix this problem ?
By the way, I am using theses parameters to generate URLs (in parameters.yml) :
Why the
request()
method does not use these parameters too ? (maybe I'm missing something).The text was updated successfully, but these errors were encountered: