-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountStatusCheckerTest.php
More file actions
74 lines (56 loc) · 2.34 KB
/
Copy pathAccountStatusCheckerTest.php
File metadata and controls
74 lines (56 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Security;
use App\Entity\User;
use App\Enum\UserStatus;
use App\Security\AccountStatusChecker;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
use Symfony\Component\Security\Core\User\UserInterface;
final class AccountStatusCheckerTest extends TestCase
{
// Tests that an Approved user passes the pre-auth hook without raising.
public function testApprovedUserPassesPreAuth(): void
{
$user = (new User())
->setName('Alice')
->setStatus(UserStatus::Approved);
(new AccountStatusChecker())->checkPreAuth($user);
// No exception thrown is the assertion; explicit to keep PHPUnit happy.
self::assertTrue(true);
}
// Ensures a Pending user is rejected with the 'account.pending' message key.
public function testPendingUserIsRejectedWithLocalisedMessage(): void
{
$user = (new User())
->setName('Pending')
->setStatus(UserStatus::Pending);
$this->expectException(CustomUserMessageAccountStatusException::class);
$this->expectExceptionMessage('account.pending');
(new AccountStatusChecker())->checkPreAuth($user);
}
// Ensures a Blocked user is rejected with the 'account.blocked' message key.
public function testBlockedUserIsRejectedWithLocalisedMessage(): void
{
$user = (new User())
->setName('Blocked')
->setStatus(UserStatus::Blocked);
$this->expectException(CustomUserMessageAccountStatusException::class);
$this->expectExceptionMessage('account.blocked');
(new AccountStatusChecker())->checkPreAuth($user);
}
// Verifies non-App User implementations fall through to the password checker.
public function testForeignUserImplementationsAreIgnored(): void
{
$foreignUser = $this->createMock(UserInterface::class);
(new AccountStatusChecker())->checkPreAuth($foreignUser);
self::assertTrue(true);
}
// Tests that checkPostAuth does nothing (required by the interface).
public function testCheckPostAuthIsANoOp(): void
{
$user = (new User())->setStatus(UserStatus::Approved);
(new AccountStatusChecker())->checkPostAuth($user);
self::assertTrue(true);
}
}