Skip to content
Closed
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
17 changes: 13 additions & 4 deletions src/Tempest/Framework/Testing/Http/HttpRouterTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Tempest\Http\Mappers\RequestToPsrRequestMapper;
use Tempest\Http\Method;
use Tempest\Http\Request;
use Tempest\Http\Response;
use Tempest\Reflection\MethodReflector;
use Tempest\Router\Exceptions\HttpExceptionHandler;
use Tempest\Router\Route;
Expand Down Expand Up @@ -239,19 +240,27 @@ public function sendRequest(Request $request): TestResponseHelper
try {
$response = $router->dispatch(map($request)->with(RequestToPsrRequestMapper::class)->do());
} catch (Throwable $throwable) {
return new TestResponseHelper(
return $this->createTestResponseHelper(
response: $this->container->get(HttpExceptionHandler::class)->renderResponse($request, $throwable),
request: $request,
container: $this->container,
throwable: $throwable,
);
}
}

return new TestResponseHelper(
return $this->createTestResponseHelper(
response: $response,
request: $request,
container: $this->container,
);
}

private function createTestResponseHelper(Response $response, Request $request, ?Throwable $throwable = null): TestResponseHelper
{
return $this->container->get(
TestResponseHelper::class,
response: $response,
request: $request,
throwable: $throwable,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

use function Tempest\Support\arr;

final class TestResponseHelper
class TestResponseHelper

Check failure on line 29 in src/Tempest/Framework/Testing/Http/TestResponseHelper.php

View workflow job for this annotation

GitHub Actions / Run static analysis: PHPStan

Tempest\Framework\Testing\Http\TestResponseHelper should be final
{
/**
* @param Response $response The original response from the controller.
Expand Down
Loading