diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6f9cc..eded91b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## v0.1.198 + +* TestUserSession: allow setting up a service account user session for unit tests + ## v0.1.197 * cron: print information about the cron jobs being run and their status to diff --git a/src/TestUtils/Internal/TestAuthenticator.php b/src/TestUtils/Internal/TestAuthenticator.php index 6ef48df..5213875 100644 --- a/src/TestUtils/Internal/TestAuthenticator.php +++ b/src/TestUtils/Internal/TestAuthenticator.php @@ -24,18 +24,16 @@ class TestAuthenticator extends AbstractAuthenticator public const TEST_TOKEN = '42'; public const TEST_AUTHORIZATION_HEADER = 'Bearer '.self::TEST_TOKEN; - /** @var TestUser */ - private $user; + private ?TestUser $user = null; - /** @var string */ - private $token; + private ?string $token = null; - public function setToken(?string $token) + public function setToken(?string $token): void { $this->token = $token; } - public function setUser(TestUser $user) + public function setUser(TestUser $user): void { $this->user = $user; } diff --git a/src/TestUtils/TestUserSession.php b/src/TestUtils/TestUserSession.php index 457f5d4..df7f3e7 100644 --- a/src/TestUtils/TestUserSession.php +++ b/src/TestUtils/TestUserSession.php @@ -8,25 +8,22 @@ class TestUserSession implements UserSessionInterface { - private ?string $userIdentifier; - private array $roles; - private bool $isAuthenticated; - - public function __construct(?string $identifier = null, array $roles = [], bool $isAuthenticated = false) + public function __construct( + private ?string $userIdentifier = null, + private array $symfonyRoles = [], + private bool $isAuthenticated = false, + private readonly bool $isServiceAccount = false) { - $this->userIdentifier = $identifier; - $this->roles = $roles; - $this->isAuthenticated = $isAuthenticated; } - public function setIdentifier(?string $identifier) + public function setIdentifier(?string $identifier): void { $this->userIdentifier = $identifier; } - public function setRoles(array $roles) + public function setRoles(array $roles): void { - $this->roles = $roles; + $this->symfonyRoles = $roles; } public function setSessionToken(?array $jwt): void @@ -35,7 +32,7 @@ public function setSessionToken(?array $jwt): void public function getUserRoles(): array { - return $this->roles; + return $this->symfonyRoles; } public function getUserIdentifier(): ?string @@ -75,6 +72,6 @@ public function getSessionTTL(): int public function isServiceAccount(): bool { - return false; + return $this->isServiceAccount; } }