Skip to content

Commit

Permalink
Add onHost to MakesHttpRequests to allow multihost testing (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerardo Rico Botella <[email protected]>
  • Loading branch information
gricob and Gerardo Rico Botella authored Jan 12, 2021
1 parent bbac868 commit 1c858b5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Concerns/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions tests/App/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
7 changes: 6 additions & 1 deletion tests/App/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ test_form:

test_headers:
path: /headers
defaults: { _controller: 'Tests\App\Controller\DefaultController::headers' }
defaults: { _controller: 'Tests\App\Controller\DefaultController::headers' }

test_host:
path: /host
host: test.com
controller: 'Tests\App\Controller\DefaultController::host'
7 changes: 7 additions & 0 deletions tests/FunctionalTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1c858b5

Please sign in to comment.