Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Fix PHPDoc for TestResponse's Response Type to \Symfony\Component\HttpFoundation\Response #52915

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
12 changes: 8 additions & 4 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
* @template TResponse of \Symfony\Component\HttpFoundation\Response
*
* @mixin \Illuminate\Http\Response
*/
class TestResponse implements ArrayAccess
Expand All @@ -46,7 +48,7 @@ class TestResponse implements ArrayAccess
/**
* The response to delegate to.
*
* @var \Illuminate\Http\Response
* @var TResponse
*/
public $baseResponse;

Expand All @@ -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
*/
Expand All @@ -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<R>
*/
public static function fromBaseResponse($response, $request = null)
{
Expand Down
25 changes: 25 additions & 0 deletions types/Testing/TestResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Testing\TestResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;

use function PHPStan\Testing\assertType;

$response = TestResponse::fromBaseResponse(response('Laravel', 200));
assertType(Response::class, $response->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);