Skip to content

Commit

Permalink
Update src/Illuminate/Testing/TestResponse.php
Browse files Browse the repository at this point in the history
Co-authored-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
kayw-geek and crynobone committed Sep 25, 2024
1 parent 1010a2d commit dd77a7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\StreamedJsonResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use function PHPStan\dumpType;

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

Expand All @@ -67,7 +70,7 @@ class TestResponse implements ArrayAccess
/**
* Create a new test response instance.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @param TResponse $response
* @param \Illuminate\Http\Request|null $request
* @return void
*/
Expand All @@ -81,9 +84,10 @@ public function __construct($response, $request = null)
/**
* Create a new TestResponse from another response.
*
* @param \Symfony\Component\HttpFoundation\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
19 changes: 10 additions & 9 deletions types/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

use function PHPStan\Testing\assertType;

$response = TestResponse::fromBaseResponse(new StreamedResponse());
assertType(Response::class, $response->baseResponse);

$response = TestResponse::fromBaseResponse(new RedirectResponse(''));
assertType(Response::class, $response->baseResponse);

$response = TestResponse::fromBaseResponse(response()->redirectTo(''));
assertType(Response::class, $response->baseResponse);
assertType(RedirectResponse::class, $response->baseResponse);

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

0 comments on commit dd77a7c

Please sign in to comment.