diff --git a/src/Server.php b/src/Server.php index 2f06932..96bd788 100644 --- a/src/Server.php +++ b/src/Server.php @@ -90,7 +90,16 @@ private function createRestfulFunction($httpMethod, $path, $function) $requestPathArray = explode('/', $requestPath); $pathArray = explode('/', $path); - if (count($requestPathArray) !== count($pathArray)) { + $countRequestPathEntries = count($requestPathArray); + if ($countRequestPathEntries !== count($pathArray)) { + return $next($request); + } + + if ($requestPath === $path) { + return $function($request, $next); + } + + if (false === strpos($path, ':')) { return $next($request); } diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 17286aa..415f26f 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -251,4 +251,23 @@ public function testUserDefinedCallbackIsNotUsed() $this->assertSame('/user/list', $requestAssertion->getUri()->getPath()); $this->assertSame('example.com', $requestAssertion->getHeaderLine('Host')); } + + public function testNoSuchCallDefinedResultInNeverCalled() + { + $requestAssertion = null; + $server = new Server(); + + $server->get('/user/anotherlist', function (ServerRequestInterface $request, callable $next) use (&$requestAssertion) { + $requestAssertion = $request; + }); + + $server->get('/user/list', function (ServerRequestInterface $request, callable $next) use (&$requestAssertion) { + $requestAssertion = $request; + }); + + $this->socket->emit('connection', array($this->connection)); + $this->connection->emit('data', array("GET http://example.com/user/anotherlista HTTP/1.0\r\n\r\n")); + + $this->assertSame(null, $requestAssertion); + } }