symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.62k stars 9.42k forks source link

BrowserKit::request does not handle network paths (Functional test for subdomains) #7323

Closed vazgen closed 11 years ago

vazgen commented 11 years ago

Hello,

There is a problem related to test for subdomains (all other tests work). Maybe I do something wrong!! I am able to access to sob-domain directly from a browser as will as I see the route in terminal app/console router:debug -e=test

the route

anf_word_scrabble_widget:
    path:   /scrabble/scrabble-finder-widget.php
    defaults:  { _controller: MyBundle:Default:widget }
    host:     w.{domain}
    requirements:
         domain: %domain%

config.yml

domain: "example.local"

test

public function testWidget()
{
   $client = static::createClient();

   $router = $client->getContainer()->get('router');
   $domain = $client->getContainer()->getParameter('domain');

  $url = $router->generate('anf_word_scrabble_widget', array('domain' => $domain));

  $crawler = $client->request('GET', $url);
  $this->assertEquals(200, $client->getResponse()->getStatusCode());
}

it throws an exception

No route found for "GET //w.example.local/scrabble/scrabble-finder-widget.php" (404 Not Found)

I have tried to use

$client = static::createClient(array(), array(
'HTTP_HOST'       => 'w.example.local',
));

but the same!

Tobion commented 11 years ago

Can you please try to use $url = $router->generate('anf_word_scrabble_widget', array('domain' => $domain), UrlGeneratorInterface::ABSOLUTE_URL); and see if that works? Because currently it generates a network path (domain does not match) and the client might not be able to request that.

vazgen commented 11 years ago

thanks @Tobion it solves the problem :+1:

Tobion commented 11 years ago

I reopen this ticket because the browserkit client should be fixed to handle network paths. I've changed the title of this ticket.

fabpot commented 11 years ago

fixed by #7179