Skip to content

Commit

Permalink
Add failing test for #298
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Jul 21, 2021
1 parent 1ca894d commit 8bdbf0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function prepareRoutes(ServerRequestInterface $request): void
$options = [];

/** @var Route $route */
foreach ($routes as $key => $route) {
foreach ($routes as $route) {
if ($route->getStrategy() === null) {
$route->setStrategy($this->getStrategy());
}
Expand All @@ -164,7 +164,7 @@ public function prepareRoutes(ServerRequestInterface $request): void
continue;
}

// need a messy but useful identifier for to determine what methods to respond with on OPTIONS
// need a messy but useful identifier to determine what methods to respond with on OPTIONS
$identifier = $route->getScheme() . static::IDENTIFIER_SEPARATOR . $route->getHost()
. static::IDENTIFIER_SEPARATOR . $route->getPort() . static::IDENTIFIER_SEPARATOR . $route->getPath();

Expand Down Expand Up @@ -228,7 +228,7 @@ protected function buildOptionsRoutes(array $options): void

protected function collectGroupRoutes(): void
{
foreach ($this->groups as $key => $group) {
foreach ($this->groups as $group) {
$group();
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/DispatchIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace League\Route;

use Exception;
use League\Route\Fixture\Controller;
use League\Route\Fixture\Middleware;
use League\Route\Http\Exception\{BadRequestException, MethodNotAllowedException, NotFoundException};
use League\Route\Strategy\JsonStrategy;
Expand Down Expand Up @@ -913,4 +914,37 @@ public function process(

$router->dispatch($request);
}

public function testCanMapSameRoutePathOnDifferentConditions(): void
{
$router = new Router();

$router
->map('GET', '/', [Controller::class, 'action'])
->setHost('test1.com')
;

$router
->map('GET', '/', [Controller::class, 'action'])
->setHost('test2.com')
;

$requestOne = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
$requestTwo = $this->getMockBuilder(ServerRequestInterface::class)->getMock();

$uriOne = $this->getMockBuilder(UriInterface::class)->getMock();
$uriTwo = $this->getMockBuilder(UriInterface::class)->getMock();

$uriOne->method('getHost')->willReturn('test1.com');
$uriTwo->method('getHost')->willReturn('test2.com');

$requestOne->method('getUri')->willReturn($uriOne);
$requestTwo->method('getUri')->willReturn($uriTwo);

$responseOne = $router->dispatch($requestOne);
self::assertSame($responseOne->getHeader('action'), 'true');

$responseTwo = $router->dispatch($requestTwo);
self::assertSame($responseTwo->getHeader('action'), 'true');
}
}

0 comments on commit 8bdbf0a

Please sign in to comment.