Skip to content

Commit

Permalink
feat(Testing): Support passing files/cookies in CreateRequest concern
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Nov 22, 2022
1 parent 5a018e3 commit e4068ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Testing/Concerns/CreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Routing\UrlGenerator;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

trait CreateRequest
Expand All @@ -15,14 +16,20 @@ trait CreateRequest
* @template TRequest of Request
*
* @param class-string<TRequest> $requestClass
* @param array<string, string|int|float|bool> $cookies
* @param array<string, array<UploadedFile>|UploadedFile> $files
* @param array<string, string|int|float|bool> $server
*
* @return TRequest
*/
public function createPostRequest(
Application $application,
string $requestClass,
array $data,
string $accept = 'application/json'
string $accept = 'application/json',
array $cookies = [],
array $files = [],
array $server = []
): object {
/** @var UrlGenerator $urlGenerator */
$urlGenerator = $application->make(UrlGenerator::class);
Expand All @@ -32,9 +39,10 @@ public function createPostRequest(
uri: $uri,
method: 'POST',
parameters: $data,
cookies: [],
files: [],
cookies: $cookies,
files: $files,
server: [
...$server,
'HTTP_ACCEPT' => $accept,
],
);
Expand Down

0 comments on commit e4068ca

Please sign in to comment.