-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 4.0.4 |
According to the documentation (http://symfony.com/doc/current/routing/hostname_pattern.html#testing-your-controllers) this test shouldn't failed :
// Controller
/**
* @Route("/test", name="test")
*/
public function test(Request $request)
{
return new Response($request->getHttpHost());
}
// Test
class TestControllerTest extends WebTestCase
{
public function testHost()
{
$client = static::createClient();
$client->request('GET', '/test', [], [], ['HTTP_HOST' => 'host.dev']);
$this->assertEquals('host.dev', $client->getResponse()->getContent());
}
public function testHost2()
{
$client = static::createClient();
$client->setServerParameter('HTTP_HOST', 'host.dev');
$client->request('GET', '/test');
$this->assertEquals('host.dev', $client->getResponse()->getContent());
}
public function testHost3()
{
$client = static::createClient([], ['HTTP_HOST', 'host.dev']);
$client->request('GET', '/test');
$this->assertEquals('host.dev', $client->getResponse()->getContent());
}
}
Actually only testHost2 success :
There were 2 failures:
1) App\Tests\Controller\TestControllerTest::testHost
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'host.dev'
+'localhost'
/home/mathieu/htdocs/thebox/tests/Controller/TestControllerTest.php:15
2) App\Tests\Controller\TestControllerTest::testHost3
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'host.dev'
+'localhost'
/home/mathieu/htdocs/thebox/tests/Controller/TestControllerTest.php:32
Metadata
Metadata
Assignees
Labels
No labels