-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathCampCollaborationUpdateProcessorTest.php
More file actions
118 lines (93 loc) · 4.53 KB
/
CampCollaborationUpdateProcessorTest.php
File metadata and controls
118 lines (93 loc) · 4.53 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace App\Tests\State;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Camp;
use App\Entity\CampCollaboration;
use App\Entity\Profile;
use App\Entity\User;
use App\Service\MailService;
use App\State\CampCollaborationUpdateProcessor;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
/**
* @internal
*/
class CampCollaborationUpdateProcessorTest extends TestCase {
use CampCollaborationTestTrait;
public const INITIAL_USER = null;
public const INITIAL_INVITE_EMAIL = null;
public const INITIAL_INVITE_KEY = null;
private CampCollaboration $campCollaboration;
private User $user;
private MailService|MockObject $mailService;
private CampCollaborationUpdateProcessor $processor;
/**
* @throws \ReflectionException
*/
protected function setUp(): void {
$camp = new Camp();
$camp->title = 'title';
$this->campCollaboration = new CampCollaboration();
$this->campCollaboration->user = self::INITIAL_USER;
$this->campCollaboration->inviteEmail = self::INITIAL_INVITE_EMAIL;
$this->campCollaboration->inviteKey = self::INITIAL_INVITE_KEY;
$this->campCollaboration->camp = $camp;
$profile = new Profile();
$profile->email = 'e@mail.com';
$this->user = new User();
$profile->user = $this->user;
$this->user->profile = $profile;
$decoratedProcessor = $this->createStub(ProcessorInterface::class);
$security = $this->createMock(Security::class);
$security->method('getUser')->willReturn($this->user);
$pwHashFactory = $this->createStub(PasswordHasherFactory::class);
$this->mailService = $this->createMock(MailService::class);
$this->processor = new CampCollaborationUpdateProcessor(
$decoratedProcessor,
$security,
$pwHashFactory,
$this->mailService,
);
}
#[AllowMockObjectsWithoutExpectations]
public function testDoesNothingOnStatusChangeWhenNoInviteEmail() {
$this->mailService->expects(self::never())->method('sendInviteToCampMail');
$result = $this->processor->onBeforeStatusChange($this->campCollaboration);
$this->processor->onAfterStatusChange($this->campCollaboration);
self::assertThat($result->user, self::equalTo(self::INITIAL_USER));
self::assertThat($result->inviteEmail, self::equalTo(self::INITIAL_INVITE_EMAIL));
self::assertThat($result->inviteKey, self::equalTo(self::INITIAL_INVITE_KEY));
}
#[AllowMockObjectsWithoutExpectations]
#[DataProvider('notInvitedStatuses')]
public function testOnStatusChangeDoesNothingIfStatusIsNotInvited(string $status) {
$this->campCollaboration->inviteEmail = 'e@mail.com';
$this->campCollaboration->status = $status;
$this->mailService->expects(self::never())->method('sendInviteToCampMail');
$result = $this->processor->onBeforeStatusChange($this->campCollaboration);
$this->processor->onAfterStatusChange($this->campCollaboration);
self::assertThat($result->user, self::equalTo(self::INITIAL_USER));
self::assertThat($result->inviteEmail, self::equalTo($this->campCollaboration->inviteEmail));
self::assertThat($result->inviteKey, self::equalTo(self::INITIAL_INVITE_KEY));
}
#[AllowMockObjectsWithoutExpectations]
public function testSendsInviteEmailIfStatusChangesToInvitedAndInviteEmailPresent() {
$this->campCollaboration->inviteEmail = 'e@mail.com';
$this->mailService->expects(self::once())->method('sendInviteToCampMail');
$result = $this->processor->onBeforeStatusChange($this->campCollaboration);
$this->processor->onAfterStatusChange($this->campCollaboration);
self::assertThat($result->inviteKey, self::logicalNot(self::isNull()));
}
#[AllowMockObjectsWithoutExpectations]
public function testSendsInviteEmailIfStatusChangesToInvitedAndUserPresent() {
$this->campCollaboration->user = $this->user;
$this->mailService->expects(self::once())->method('sendInviteToCampMail');
$result = $this->processor->onBeforeStatusChange($this->campCollaboration);
$this->processor->onAfterStatusChange($this->campCollaboration);
self::assertThat($result->inviteKey, self::logicalNot(self::isNull()));
}
}