Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public function match(Request $request, bool $fresh = true): ?Route
* @param Route $route
* @param Request $request
*/
public function execute(Route $route, Request $request): static
public function execute(Route $route, Request $request, Response $response): static
{
$arguments = [];
$groups = $route->getGroups();
Expand All @@ -720,8 +720,10 @@ public function execute(Route $route, Request $request): static
}
}

$arguments = $this->getArguments($route, $pathValues, $request->getParams());
\call_user_func_array($route->getAction(), $arguments);
if (!$response->isSent()) {
$arguments = $this->getArguments($route, $pathValues, $request->getParams());
\call_user_func_array($route->getAction(), $arguments);
}
Comment on lines +723 to +726
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No unit test for the new guard

The PR description lists three test-plan items (all unchecked). There is no new test case in tests/HttpTest.php or the e2e suite that verifies an init hook calling $response->send() actually skips the route action while still executing shutdown hooks. Without a test, a future refactor could silently regress this behavior.


foreach ($groups as $group) {
foreach (self::$shutdown as $hook) { // Group shutdown hooks
Expand Down Expand Up @@ -953,7 +955,7 @@ private function runInternal(Request $request, Response $response): static
}

if (null !== $route) {
return $this->execute($route, $request);
return $this->execute($route, $request, $response);
} elseif (self::REQUEST_METHOD_OPTIONS == $method) {
try {
foreach ($groups as $group) {
Expand Down
24 changes: 12 additions & 12 deletions tests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testCanExecuteRoute(): void
});

\ob_start();
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -132,7 +132,7 @@ public function testCanExecuteRoute(): void
\ob_start();
$request = new UtopiaFPMRequestTest();
$request::_setParams(['x' => 'param-x', 'y' => 'param-y', 'z' => 'param-z']);
$this->http->execute($route, $request);
$this->http->execute($route, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -152,7 +152,7 @@ public function testCanExecuteRoute(): void
\ob_start();
$request = new UtopiaFPMRequestTest();
$request::_setParams(['x' => 'param-x', 'y' => 'param-y']);
$this->http->execute($route, $request);
$this->http->execute($route, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand Down Expand Up @@ -224,7 +224,7 @@ public function testCanExecuteRoute(): void
\ob_start();
$request = new UtopiaFPMRequestTest();
$request::_setParams(['x' => 'param-x', 'y' => 'param-y']);
$this->http->execute($route, $request);
$this->http->execute($route, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -234,7 +234,7 @@ public function testCanExecuteRoute(): void
\ob_start();
$request = new UtopiaFPMRequestTest();
$request::_setParams(['x' => 'param-x', 'y' => 'param-y']);
$this->http->execute($homepage, $request);
$this->http->execute($homepage, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand Down Expand Up @@ -264,7 +264,7 @@ public function testCanAddAndExecuteHooks()
});

\ob_start();
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -280,7 +280,7 @@ public function testCanAddAndExecuteHooks()
});

\ob_start();
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand Down Expand Up @@ -348,15 +348,15 @@ public function testCanHookThrowExceptions()
});

\ob_start();
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

$this->assertEquals('error-Param "y" is not optional.', $result);

\ob_start();
$_GET['y'] = 'y-def';
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand Down Expand Up @@ -606,7 +606,7 @@ public function testCallableStringParametersNotExecuted(): void
});

\ob_start();
$this->http->execute($route, new Request());
$this->http->execute($route, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -624,7 +624,7 @@ public function testCallableStringParametersNotExecuted(): void
\ob_start();
$request = new UtopiaFPMRequestTest();
$request::_setParams(['func' => 'system']);
$this->http->execute($route2, $request);
$this->http->execute($route2, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand All @@ -642,7 +642,7 @@ public function testCallableStringParametersNotExecuted(): void
});

\ob_start();
$this->http->execute($route3, new Request());
$this->http->execute($route3, new Request(), new Response());
$result = \ob_get_contents();
\ob_end_clean();

Expand Down
Loading