Skip to content

Commit

Permalink
feat(Testing): CreateRequest now accept user parameter that is passed…
Browse files Browse the repository at this point in the history
… to request

- request->user() now will return given user
  • Loading branch information
pionl committed Sep 5, 2023
1 parent 60da0a8 commit 872fe0c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Testing/Concerns/CreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace LaraStrict\Testing\Concerns;

use Closure;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Foundation\Http\FormRequest;
Expand Down Expand Up @@ -82,7 +83,8 @@ protected function createFormRequest(
array $cookies = [],
array $files = [],
array $server = [],
array $makeBindings = []
array $makeBindings = [],
Authenticatable $user = null,
): Request {
$symfonyRequest = SymfonyRequest::create(
uri: 'https://testing',
Expand All @@ -96,18 +98,22 @@ protected function createFormRequest(
],
);

$requestClass = $requestClass::createFromBase($symfonyRequest);
$request = $requestClass::createFromBase($symfonyRequest);

$requestClass->setContainer(
$request->setContainer(
new TestingContainer(
makeBindings: $makeBindings,
makeAlwaysBinding: static fn (array $parameters, string $class) => new $class(...$parameters)
)
);

$requestClass->setValidator(new ValidatorMock($data));
$requestClass->validateResolved();
if ($user !== null) {
$request->setUserResolver(static fn () => $user);
}

return $requestClass;
$request->setValidator(new ValidatorMock($data));
$request->validateResolved();

return $request;
}
}

0 comments on commit 872fe0c

Please sign in to comment.