Skip to content

Commit 16f3b20

Browse files
committed
replace request target with path
1 parent 8b072b4 commit 16f3b20

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/Router.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,23 @@ public function match(ServerRequestInterface $request): RouteInterface
6161
{
6262
$this->urlMatcher->setContext($this->getRequestContext($request));
6363

64+
$path = $request->getUri()->getPath();
65+
6466
try {
65-
$parameters = $this->urlMatcher->match($request->getUri()->getPath());
67+
$parameters = $this->urlMatcher->match($path);
6668
} catch (SymfonyResourceNotFoundException) {
6769
throw HttpException::createNotFound([
6870
'detail' => \sprintf(
69-
'The page "%s" you are looking for could not be found.'
70-
.' Check the address bar to ensure your URL is spelled correctly.',
71-
$request->getRequestTarget()
71+
'The path "%s" you are looking for could not be found.',
72+
$path
7273
),
7374
]);
7475
} catch (SymfonyMethodNotAllowedException $exception) {
7576
throw HttpException::createMethodNotAllowed([
7677
'detail' => \sprintf(
7778
'Method "%s" at path "%s" is not allowed. Must be one of: "%s"',
7879
$request->getMethod(),
79-
$request->getRequestTarget(),
80+
$path,
8081
implode('", "', $exception->getAllowedMethods()),
8182
),
8283
]);

tests/Integration/RouterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static function (ServerRequestInterface $request) use ($responseFactory) {
9494

9595
self::assertSame(404, $response->getStatusCode());
9696
self::assertStringContainsString(
97-
'The page "/hello" you are looking for could not be found.',
97+
'The path "/hello" you are looking for could not be found.',
9898
(string) $response->getBody()
9999
);
100100
}

tests/Unit/RouterTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public function testMatchNotFound(): void
9797
new WithReturn('getUri', [], $uri),
9898
new WithReturn('getMethod', [], 'GET'),
9999
new WithReturn('getUri', [], $uri),
100-
new WithReturn('getRequestTarget', [], '/'),
101100
]);
102101

103102
/** @var RouteInterface $route */
@@ -121,7 +120,7 @@ public function testMatchNotFound(): void
121120
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
122121
'status' => 404,
123122
'title' => 'Not Found',
124-
'detail' => 'The page "/" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
123+
'detail' => 'The path "/" you are looking for could not be found.',
125124
'instance' => null,
126125
], $e->jsonSerialize());
127126
}
@@ -147,7 +146,6 @@ public function testMatchMethodNotAllowed(): void
147146
new WithReturn('getMethod', [], 'POST'),
148147
new WithReturn('getUri', [], $uri),
149148
new WithReturn('getMethod', [], 'POST'),
150-
new WithReturn('getRequestTarget', [], '/api/pets?offset=1&limit=20'),
151149
]);
152150

153151
/** @var RouteInterface $route */
@@ -171,7 +169,7 @@ public function testMatchMethodNotAllowed(): void
171169
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.6',
172170
'status' => 405,
173171
'title' => 'Method Not Allowed',
174-
'detail' => 'Method "POST" at path "/api/pets?offset=1&limit=20" is not allowed. Must be one of: "GET"',
172+
'detail' => 'Method "POST" at path "/api/pets" is not allowed. Must be one of: "GET"',
175173
'instance' => null,
176174
], $e->jsonSerialize());
177175
}
@@ -234,7 +232,6 @@ public function testMatchWithTokensNotMatch(): void
234232
new WithReturn('getUri', [], $uri),
235233
new WithReturn('getMethod', [], 'GET'),
236234
new WithReturn('getUri', [], $uri),
237-
new WithReturn('getRequestTarget', [], '/api/pets/1'),
238235
]);
239236

240237
/** @var RouteInterface $route */
@@ -258,7 +255,7 @@ public function testMatchWithTokensNotMatch(): void
258255
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
259256
'status' => 404,
260257
'title' => 'Not Found',
261-
'detail' => 'The page "/api/pets/1" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
258+
'detail' => 'The path "/api/pets/1" you are looking for could not be found.',
262259
'instance' => null,
263260
], $e->jsonSerialize());
264261
}
@@ -319,7 +316,6 @@ public function testHostMatchNotFound(): void
319316
new WithReturn('getUri', [], $uri),
320317
new WithReturn('getMethod', [], 'GET'),
321318
new WithReturn('getUri', [], $uri),
322-
new WithReturn('getRequestTarget', [], '/api/pets'),
323319
]);
324320

325321
/** @var RouteInterface $route */
@@ -343,7 +339,7 @@ public function testHostMatchNotFound(): void
343339
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
344340
'status' => 404,
345341
'title' => 'Not Found',
346-
'detail' => 'The page "/api/pets" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
342+
'detail' => 'The path "/api/pets" you are looking for could not be found.',
347343
'instance' => null,
348344
], $e->jsonSerialize());
349345
}
@@ -404,7 +400,6 @@ public function testSchemeMatchNotFound(): void
404400
new WithReturn('getUri', [], $uri),
405401
new WithReturn('getMethod', [], 'GET'),
406402
new WithReturn('getUri', [], $uri),
407-
new WithReturn('getRequestTarget', [], '/api/pets?key=value'),
408403
]);
409404

410405
/** @var RouteInterface $route */
@@ -428,7 +423,7 @@ public function testSchemeMatchNotFound(): void
428423
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
429424
'status' => 404,
430425
'title' => 'Not Found',
431-
'detail' => 'The page "/api/pets?key=value" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
426+
'detail' => 'The path "/api/pets" you are looking for could not be found.',
432427
'instance' => null,
433428
], $e->jsonSerialize());
434429
}
@@ -491,7 +486,6 @@ public function testConditionMatchNotFound(): void
491486
new WithReturn('getUri', [], $uri),
492487
new WithReturn('getMethod', [], 'GET'),
493488
new WithReturn('getUri', [], $uri),
494-
new WithReturn('getRequestTarget', [], '/api/pets?key=value'),
495489
]);
496490

497491
/** @var RouteInterface $route */
@@ -515,7 +509,7 @@ public function testConditionMatchNotFound(): void
515509
'type' => 'https://datatracker.ietf.org/doc/html/rfc2616#section-10.4.5',
516510
'status' => 404,
517511
'title' => 'Not Found',
518-
'detail' => 'The page "/api/pets?key=value" you are looking for could not be found. Check the address bar to ensure your URL is spelled correctly.',
512+
'detail' => 'The path "/api/pets" you are looking for could not be found.',
519513
'instance' => null,
520514
], $e->jsonSerialize());
521515
}

0 commit comments

Comments
 (0)