Skip to content

Commit

Permalink
Fixed JWT Token Manager proxy build in the newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
igoryok-zp committed Oct 26, 2024
1 parent a9f92ce commit c5e3d75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/tests/Service/ServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class ServiceTestCase extends KernelTestCase
/**
* @template T of object
* @param class-string<T> $class
* @param array<string, mixed> $params
* @return MockObject&T
*/
protected function buildProxy(string $class): mixed
protected function buildProxy(string $class, $params = []): mixed
{
$reflection = new ReflectionClass($class);
if ($reflection->isInterface()) {
Expand All @@ -30,10 +31,10 @@ protected function buildProxy(string $class): mixed
$constructorArguments = [];
if ($reflection->getConstructor()) {
foreach ($reflection->getConstructor()->getParameters() as $param) {
$constructorArgument = null;
$constructorArgument = $params[$param->name] ?? null;
/** @var class-string<object> */
$type = (string) $param->getType();
if (!empty($type)) {
if (empty($constructorArgument) && !empty($type)) {
$constructorArgument = $param->isDefaultValueAvailable()
? $this->getServiceOrNull($type)
: $this->getService($type);
Expand Down
4 changes: 3 additions & 1 deletion app/tests/Service/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class UserServiceTest extends ServiceTestCase

private function createService(?int $contextUserId = null): UserService
{
$this->tokenManager = $this->buildProxy(JWTTokenManagerInterface::class);
$this->tokenManager = $this->buildProxy(JWTTokenManagerInterface::class, [
'userIdClaim' => static::getContainer()->getParameter('lexik_jwt_authentication.user_id_claim'),
]);

return new UserService(
$this->createContext($contextUserId),
Expand Down

0 comments on commit c5e3d75

Please sign in to comment.