diff --git a/src/Concerns/MakesHttpRequests.php b/src/Concerns/MakesHttpRequests.php index 03445f6..b4f73be 100644 --- a/src/Concerns/MakesHttpRequests.php +++ b/src/Concerns/MakesHttpRequests.php @@ -133,6 +133,13 @@ protected function withHeaders(array $headers): self return $this; } + protected function onHost(string $host): self + { + $this->server['HTTP_HOST'] = $host; + + return $this; + } + protected function click(Link $link): TestResponse { return $this->request($link->getMethod(), $link->getUri()); diff --git a/tests/App/Controller/DefaultController.php b/tests/App/Controller/DefaultController.php index 4214c22..69265d1 100644 --- a/tests/App/Controller/DefaultController.php +++ b/tests/App/Controller/DefaultController.php @@ -98,6 +98,11 @@ public function headers(Request $request) return new Response($html); } + public function host(Request $request) + { + return new Response($request->getHost()); + } + private function ensureJsonRequest(Request $request) { if ($request->headers->get('Content-Type') != 'application/json') { diff --git a/tests/App/routing.yml b/tests/App/routing.yml index 67f1e9b..f3bba83 100644 --- a/tests/App/routing.yml +++ b/tests/App/routing.yml @@ -40,4 +40,9 @@ test_form: test_headers: path: /headers - defaults: { _controller: 'Tests\App\Controller\DefaultController::headers' } \ No newline at end of file + defaults: { _controller: 'Tests\App\Controller\DefaultController::headers' } + +test_host: + path: /host + host: test.com + controller: 'Tests\App\Controller\DefaultController::host' \ No newline at end of file diff --git a/tests/FunctionalTestCaseTest.php b/tests/FunctionalTestCaseTest.php index 0497075..2af0742 100644 --- a/tests/FunctionalTestCaseTest.php +++ b/tests/FunctionalTestCaseTest.php @@ -235,6 +235,13 @@ public function testContainerCanGetUnusedServiceWhenUsingPreventRemoveUnusedDefi $this->assertInstanceOf(UnusedService::class, $container->get('test.unused_private_service')); } + public function testOnHost() + { + $this->catchExceptions()->get('/host')->assertNotFound(); + + $this->onHost('test.com')->get('/host')->assertOk()->assertSee('test.com'); + } + private function getTestFile() { return new UploadedFile(