diff --git a/src/Regex/Matcher.php b/src/Regex/Matcher.php index 45f7084..4f3eaee 100644 --- a/src/Regex/Matcher.php +++ b/src/Regex/Matcher.php @@ -34,6 +34,14 @@ public function match(string $toMatch): Result throw new NoMatchFoundException('No matches found in the regex'); } + return $this->build($matches); + } + + /** + * @param string[] $matches + */ + private function build(array $matches): Result + { $id = null; $parameters = []; foreach ($matches as $index => $match) { @@ -42,7 +50,7 @@ public function match(string $toMatch): Result break; } - if ($index === 0) { + if ($index === 0 || $match === '') { continue; } diff --git a/tests/RegexHttpRouterTest.php b/tests/RegexHttpRouterTest.php index 45b18fd..a023795 100644 --- a/tests/RegexHttpRouterTest.php +++ b/tests/RegexHttpRouterTest.php @@ -41,7 +41,6 @@ public function testShouldRoute(): void $request->expects($this->once()) ->method('getMethod') ->willReturn('get'); - $this->expectException(RouterException::class); $request->expects($this->once()) ->method('getRequestTarget') @@ -57,7 +56,6 @@ public function testShouldRoute(): void $request->expects($this->once()) ->method('getMethod') ->willReturn('get'); - $this->expectException(RouterException::class); $request->expects($this->once()) ->method('getRequestTarget') @@ -74,7 +72,6 @@ public function testShouldRoute(): void $request->expects($this->once()) ->method('getMethod') ->willReturn('post'); - $this->expectException(RouterException::class); $request->expects($this->once()) ->method('getRequestTarget')