Skip to content

Commit

Permalink
TestUserSession: allow setting up a service account user session for …
Browse files Browse the repository at this point in the history
…unit tests
  • Loading branch information
tobiasgv committed Jan 8, 2025
1 parent 5e21f69 commit 153e58d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/TestUtils/Internal/TestAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 10 additions & 13 deletions src/TestUtils/TestUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +32,7 @@ public function setSessionToken(?array $jwt): void

public function getUserRoles(): array
{
return $this->roles;
return $this->symfonyRoles;
}

public function getUserIdentifier(): ?string
Expand Down Expand Up @@ -75,6 +72,6 @@ public function getSessionTTL(): int

public function isServiceAccount(): bool
{
return false;
return $this->isServiceAccount;
}
}

0 comments on commit 153e58d

Please sign in to comment.