11
11
use Doctrine \ORM \EntityManagerInterface ;
12
12
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
13
13
14
+ /**
15
+ * @internal
16
+ */
14
17
class ClaimInvitationServiceTest extends KernelTestCase {
15
-
16
18
private CampCollaborationRepository $ campCollaborationRepository ;
17
19
private EntityManagerInterface $ em ;
18
20
private ClaimInvitationService $ claimInvitationService ;
19
21
20
22
private User $ user ;
21
23
private string $ email = 'test@example.com ' ;
22
24
23
-
24
25
protected function setUp (): void {
25
26
static ::bootKernel ();
26
27
@@ -38,7 +39,8 @@ public function testDoesNothingWhenNoInvitationPresent() {
38
39
->expects ($ this ->once ())
39
40
->method ('findAllByInviteEmailAndInvited ' )
40
41
->with ($ this ->email )
41
- ->willReturn ([]);
42
+ ->willReturn ([])
43
+ ;
42
44
43
45
// then
44
46
$ this ->em ->expects ($ this ->never ())->method ('persist ' );
@@ -61,7 +63,8 @@ public function testClaimsInvitation() {
61
63
->expects ($ this ->once ())
62
64
->method ('findAllByInviteEmailAndInvited ' )
63
65
->with ($ this ->email )
64
- ->willReturn ([ $ invitation ]);
66
+ ->willReturn ([$ invitation ])
67
+ ;
65
68
66
69
// then
67
70
$ this ->em ->expects ($ this ->once ())->method ('persist ' )->with ($ invitation );
@@ -97,13 +100,15 @@ public function testIgnoresInvitationWhenUserAlreadyPartOfCamp() {
97
100
->expects ($ this ->once ())
98
101
->method ('findAllByInviteEmailAndInvited ' )
99
102
->with ($ this ->email )
100
- ->willReturn ([ $ invitation ]);
103
+ ->willReturn ([$ invitation ])
104
+ ;
101
105
102
106
$ this ->campCollaborationRepository
103
107
->expects ($ this ->once ())
104
108
->method ('findOneBy ' )
105
109
->with (['user ' => $ this ->user , 'camp ' => $ camp ])
106
- ->willReturn ($ existingCollaboration );
110
+ ->willReturn ($ existingCollaboration )
111
+ ;
107
112
108
113
// then
109
114
$ this ->em ->expects ($ this ->never ())->method ('persist ' );
@@ -139,13 +144,15 @@ public function testIgnoresInvitationWhenUserWasPreviouslyPartOfCamp() {
139
144
->expects ($ this ->once ())
140
145
->method ('findAllByInviteEmailAndInvited ' )
141
146
->with ($ this ->email )
142
- ->willReturn ([ $ invitation ]);
147
+ ->willReturn ([$ invitation ])
148
+ ;
143
149
144
150
$ this ->campCollaborationRepository
145
151
->expects ($ this ->once ())
146
152
->method ('findOneBy ' )
147
153
->with (['user ' => $ this ->user , 'camp ' => $ camp ])
148
- ->willReturn ($ existingCollaboration );
154
+ ->willReturn ($ existingCollaboration )
155
+ ;
149
156
150
157
// then
151
158
$ this ->em ->expects ($ this ->never ())->method ('persist ' );
@@ -181,24 +188,30 @@ public function testHandlesUniqueConstraintViolationWhenUserAlreadyPartOfCamp()
181
188
->expects ($ this ->once ())
182
189
->method ('findAllByInviteEmailAndInvited ' )
183
190
->with ($ this ->email )
184
- ->willReturn ([ $ invitation , $ invitation2 ]);
191
+ ->willReturn ([$ invitation , $ invitation2 ])
192
+ ;
185
193
186
194
// then
187
195
$ matcher1 = $ this ->exactly (2 );
188
196
$ this ->em ->expects ($ matcher1 )
189
197
->method ('persist ' )
190
198
->willReturnCallback (function (CampCollaboration $ value ) use ($ matcher1 , $ invitation , $ invitation2 ) {
191
- if ($ matcher1 ->numberOfInvocations () === 1 ) $ this ->assertEquals ($ invitation , $ value );
192
- else $ this ->assertEquals ($ invitation2 , $ value );
193
- });
199
+ if (1 === $ matcher1 ->numberOfInvocations ()) {
200
+ $ this ->assertEquals ($ invitation , $ value );
201
+ } else {
202
+ $ this ->assertEquals ($ invitation2 , $ value );
203
+ }
204
+ })
205
+ ;
194
206
$ matcher2 = $ this ->exactly (2 );
195
207
$ this ->em ->expects ($ matcher2 )
196
208
->method ('flush ' )
197
209
->willReturnCallback (function () use ($ matcher2 ) {
198
- if ($ matcher2 ->numberOfInvocations () === 1 ) {
210
+ if (1 === $ matcher2 ->numberOfInvocations ()) {
199
211
throw $ this ->createMock (UniqueConstraintViolationException::class);
200
212
}
201
- });
213
+ })
214
+ ;
202
215
$ this ->em ->expects ($ this ->once ())->method ('clear ' );
203
216
204
217
// when
0 commit comments