diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index d1958590914..93e4d2c023e 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -28,6 +28,8 @@ use Symfony\Component\HttpFoundation\StreamedResponse; /** + * @template TResponse of \Symfony\Component\HttpFoundation\Response + * * @mixin \Illuminate\Http\Response */ class TestResponse implements ArrayAccess @@ -46,7 +48,7 @@ class TestResponse implements ArrayAccess /** * The response to delegate to. * - * @var \Illuminate\Http\Response + * @var TResponse */ public $baseResponse; @@ -67,7 +69,7 @@ class TestResponse implements ArrayAccess /** * Create a new test response instance. * - * @param \Illuminate\Http\Response $response + * @param TResponse $response * @param \Illuminate\Http\Request|null $request * @return void */ @@ -81,9 +83,11 @@ public function __construct($response, $request = null) /** * Create a new TestResponse from another response. * - * @param \Illuminate\Http\Response $response + * @template R of TResponse + * + * @param R $response * @param \Illuminate\Http\Request|null $request - * @return static + * @return static */ public static function fromBaseResponse($response, $request = null) { diff --git a/types/Testing/TestResponse.php b/types/Testing/TestResponse.php new file mode 100644 index 00000000000..0aec88e033a --- /dev/null +++ b/types/Testing/TestResponse.php @@ -0,0 +1,25 @@ +baseResponse); + +$response = TestResponse::fromBaseResponse(response()->redirectTo('')); +assertType(RedirectResponse::class, $response->baseResponse); + +$response = TestResponse::fromBaseResponse(response()->download('')); +assertType(BinaryFileResponse::class, $response->baseResponse); + +$response = TestResponse::fromBaseResponse(response()->json()); +assertType(JsonResponse::class, $response->baseResponse); + +$response = TestResponse::fromBaseResponse(response()->streamDownload(fn () => 1)); +assertType(StreamedResponse::class, $response->baseResponse);