From ad87acbc1ab2196dcf4e1fbe42cd203a604270ae Mon Sep 17 00:00:00 2001 From: Illia Antypenko Date: Mon, 6 Jul 2026 20:01:56 +0200 Subject: [PATCH 1/2] EVA-3177: strip query string from endpoint path when registering routes Endpoint paths may contain a query string template (e.g. "/v1/cars?ids={ids}") that API clients use to build request URIs. Symfony matches routes against the path info only, so a route registered with the query string in its path can never match. Strip everything from "?" onward before creating the route. Request DTO population is unaffected: ServiceRequestResolver already reads query parameters from the actual request. Co-Authored-By: Claude Fable 5 --- Routing/EndpointLoader.php | 12 ++++- Tests/Routing/EndpointLoaderTest.php | 80 ++++++++++++++++++++++++++++ Tests/Routing/RequestStub.php | 20 +++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 Tests/Routing/EndpointLoaderTest.php create mode 100644 Tests/Routing/RequestStub.php diff --git a/Routing/EndpointLoader.php b/Routing/EndpointLoader.php index 2099b41..24ab4b8 100644 --- a/Routing/EndpointLoader.php +++ b/Routing/EndpointLoader.php @@ -59,7 +59,7 @@ public function load($resource, $type = null): object //TODO: go through $requestClass and set requirements \d+ etc based on type $route = new Route( - $endpoint->getPath(), + $this->stripQueryString($endpoint->getPath()), ['_controller' => $controller] ); $route->setMethods([$endpoint->getMethod()]); @@ -77,4 +77,14 @@ public function supports($resource, $type = null): bool { return 'endpoint_handler' === $type; } + + /** + * Endpoint paths may contain a query string template (e.g. "/v1/cars?ids={ids}") used by API clients + * to build request URIs. Routes are matched against the path info only, so the query string must not + * be part of the route path. + */ + private function stripQueryString(string $path): string + { + return explode('?', $path, 2)[0]; + } } diff --git a/Tests/Routing/EndpointLoaderTest.php b/Tests/Routing/EndpointLoaderTest.php new file mode 100644 index 0000000..a6a25f4 --- /dev/null +++ b/Tests/Routing/EndpointLoaderTest.php @@ -0,0 +1,80 @@ +loadRoutes('/v1/items?excludeIds={excludeIds}', 'GET'); + + $route = $routes->get(RequestStub::class); + $this->assertNotNull($route); + $this->assertSame('/v1/items', $route->getPath()); + $this->assertSame(['GET'], $route->getMethods()); + } + + public function testLoadKeepsPathPlaceholders(): void + { + $routes = $this->loadRoutes('/v1/cars/{id}', 'POST'); + + $route = $routes->get(RequestStub::class); + $this->assertNotNull($route); + $this->assertSame('/v1/cars/{id}', $route->getPath()); + $this->assertSame(['POST'], $route->getMethods()); + } + + public function testRouteWithQueryStringTemplateMatchesRequestWithoutQueryParams(): void + { + $routes = $this->loadRoutes('/v1/items?excludeIds={excludeIds}', 'GET'); + + $matcher = new UrlMatcher($routes, new RequestContext('', 'GET')); + $parameters = $matcher->match('/v1/items'); + + $this->assertSame(self::CONTROLLER, $parameters['_controller']); + $this->assertSame(RequestStub::class, $parameters['_route']); + } + + private function loadRoutes(string $path, string $method): RouteCollection + { + $endpointProphecy = $this->prophesize(EndpointInterface::class); + $endpointProphecy->getPath()->willReturn($path); + $endpointProphecy->getMethod()->willReturn($method); + + $endpointRegistryProphecy = $this->prophesize(EndpointRegistryInterface::class); + $endpointRegistryProphecy->getEndpoint(Argument::type(RequestStub::class)) + ->willReturn($endpointProphecy->reveal()); + + $endpointLoader = new EndpointLoader( + $endpointRegistryProphecy->reveal(), + [self::CONTROLLER => RequestStub::class] + ); + + $routes = $endpointLoader->load('.', 'endpoint_handler'); + $this->assertInstanceOf(RouteCollection::class, $routes); + + return $routes; + } +} diff --git a/Tests/Routing/RequestStub.php b/Tests/Routing/RequestStub.php new file mode 100644 index 0000000..faf1326 --- /dev/null +++ b/Tests/Routing/RequestStub.php @@ -0,0 +1,20 @@ + Date: Tue, 7 Jul 2026 21:34:27 +0200 Subject: [PATCH 2/2] =?UTF-8?q?EVA-3177:=20address=20review=20=E2=80=94=20?= =?UTF-8?q?use=20Endpoint=20DTO,=20drop=20integration-style=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the concrete Endpoint DTO instead of prophesizing EndpointInterface (it is just a DTO), and remove the UrlMatcher-based test which exercised Symfony routing rather than EndpointLoader itself. Co-Authored-By: Claude Opus 4.8 (1M context) --- Tests/Routing/EndpointLoaderTest.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Tests/Routing/EndpointLoaderTest.php b/Tests/Routing/EndpointLoaderTest.php index a6a25f4..5084ff9 100644 --- a/Tests/Routing/EndpointLoaderTest.php +++ b/Tests/Routing/EndpointLoaderTest.php @@ -13,13 +13,11 @@ namespace Tests\Auto1\ServiceAPIHandlerBundle\Routing; -use Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointInterface; +use Auto1\ServiceAPIComponentsBundle\Service\Endpoint\Endpoint; use Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointRegistryInterface; use Auto1\ServiceAPIHandlerBundle\Routing\EndpointLoader; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Symfony\Component\Routing\Matcher\UrlMatcher; -use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; class EndpointLoaderTest extends TestCase @@ -46,26 +44,15 @@ public function testLoadKeepsPathPlaceholders(): void $this->assertSame(['POST'], $route->getMethods()); } - public function testRouteWithQueryStringTemplateMatchesRequestWithoutQueryParams(): void - { - $routes = $this->loadRoutes('/v1/items?excludeIds={excludeIds}', 'GET'); - - $matcher = new UrlMatcher($routes, new RequestContext('', 'GET')); - $parameters = $matcher->match('/v1/items'); - - $this->assertSame(self::CONTROLLER, $parameters['_controller']); - $this->assertSame(RequestStub::class, $parameters['_route']); - } - private function loadRoutes(string $path, string $method): RouteCollection { - $endpointProphecy = $this->prophesize(EndpointInterface::class); - $endpointProphecy->getPath()->willReturn($path); - $endpointProphecy->getMethod()->willReturn($method); + $endpoint = (new Endpoint()) + ->setPath($path) + ->setMethod($method); $endpointRegistryProphecy = $this->prophesize(EndpointRegistryInterface::class); $endpointRegistryProphecy->getEndpoint(Argument::type(RequestStub::class)) - ->willReturn($endpointProphecy->reveal()); + ->willReturn($endpoint); $endpointLoader = new EndpointLoader( $endpointRegistryProphecy->reveal(),