Completed
Push — ezp-30616-follow-up ( 2e0607...b74676 )
by
unknown
35:08 queued 20:12
created

testUnAssignUserFromUserGroupStopPropagationInBeforeEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 32
loc 32
rs 9.408
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Event\Tests;
8
9
use eZ\Publish\API\Repository\Events\User\AssignUserToUserGroupEvent as AssignUserToUserGroupEventInterface;
10
use eZ\Publish\API\Repository\Events\User\BeforeAssignUserToUserGroupEvent as BeforeAssignUserToUserGroupEventInterface;
11
use eZ\Publish\API\Repository\Events\User\BeforeCreateUserEvent as BeforeCreateUserEventInterface;
12
use eZ\Publish\API\Repository\Events\User\BeforeCreateUserGroupEvent as BeforeCreateUserGroupEventInterface;
13
use eZ\Publish\API\Repository\Events\User\BeforeDeleteUserEvent as BeforeDeleteUserEventInterface;
14
use eZ\Publish\API\Repository\Events\User\BeforeDeleteUserGroupEvent as BeforeDeleteUserGroupEventInterface;
15
use eZ\Publish\API\Repository\Events\User\BeforeMoveUserGroupEvent as BeforeMoveUserGroupEventInterface;
16
use eZ\Publish\API\Repository\Events\User\BeforeUnAssignUserFromUserGroupEvent as BeforeUnAssignUserFromUserGroupEventInterface;
17
use eZ\Publish\API\Repository\Events\User\BeforeUpdateUserEvent as BeforeUpdateUserEventInterface;
18
use eZ\Publish\API\Repository\Events\User\BeforeUpdateUserGroupEvent as BeforeUpdateUserGroupEventInterface;
19
use eZ\Publish\API\Repository\Events\User\BeforeUpdateUserTokenEvent as BeforeUpdateUserTokenEventInterface;
20
use eZ\Publish\API\Repository\Events\User\CreateUserEvent as CreateUserEventInterface;
21
use eZ\Publish\API\Repository\Events\User\CreateUserGroupEvent as CreateUserGroupEventInterface;
22
use eZ\Publish\API\Repository\Events\User\DeleteUserEvent as DeleteUserEventInterface;
23
use eZ\Publish\API\Repository\Events\User\DeleteUserGroupEvent as DeleteUserGroupEventInterface;
24
use eZ\Publish\API\Repository\Events\User\MoveUserGroupEvent as MoveUserGroupEventInterface;
25
use eZ\Publish\API\Repository\Events\User\UnAssignUserFromUserGroupEvent as UnAssignUserFromUserGroupEventInterface;
26
use eZ\Publish\API\Repository\Events\User\UpdateUserEvent as UpdateUserEventInterface;
27
use eZ\Publish\API\Repository\Events\User\UpdateUserGroupEvent as UpdateUserGroupEventInterface;
28
use eZ\Publish\API\Repository\Events\User\UpdateUserTokenEvent as UpdateUserTokenEventInterface;
29
use eZ\Publish\API\Repository\UserService as UserServiceInterface;
30
use eZ\Publish\API\Repository\Values\User\User;
31
use eZ\Publish\API\Repository\Values\User\UserCreateStruct;
32
use eZ\Publish\API\Repository\Values\User\UserGroup;
33
use eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct;
34
use eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct;
35
use eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct;
36
use eZ\Publish\API\Repository\Values\User\UserUpdateStruct;
37
use eZ\Publish\Core\Event\UserService;
38
39
class UserServiceTest extends AbstractServiceTest
40
{
41 View Code Duplication
    public function testUpdateUserGroupEvents()
42
    {
43
        $traceableEventDispatcher = $this->getEventDispatcher(
44
            BeforeUpdateUserGroupEventInterface::class,
45
            UpdateUserGroupEventInterface::class
46
        );
47
48
        $parameters = [
49
            $this->createMock(UserGroup::class),
50
            $this->createMock(UserGroupUpdateStruct::class),
51
        ];
52
53
        $updatedUserGroup = $this->createMock(UserGroup::class);
54
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
55
        $innerServiceMock->method('updateUserGroup')->willReturn($updatedUserGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
57
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
58
        $result = $service->updateUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserGroup() misses a required argument $userGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
59
60
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
61
62
        $this->assertSame($updatedUserGroup, $result);
63
        $this->assertSame($calledListeners, [
64
            [BeforeUpdateUserGroupEventInterface::class, 0],
65
            [UpdateUserGroupEventInterface::class, 0],
66
        ]);
67
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
68
    }
69
70 View Code Duplication
    public function testReturnUpdateUserGroupResultInBeforeEvents()
71
    {
72
        $traceableEventDispatcher = $this->getEventDispatcher(
73
            BeforeUpdateUserGroupEventInterface::class,
74
            UpdateUserGroupEventInterface::class
75
        );
76
77
        $parameters = [
78
            $this->createMock(UserGroup::class),
79
            $this->createMock(UserGroupUpdateStruct::class),
80
        ];
81
82
        $updatedUserGroup = $this->createMock(UserGroup::class);
83
        $eventUpdatedUserGroup = $this->createMock(UserGroup::class);
84
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
85
        $innerServiceMock->method('updateUserGroup')->willReturn($updatedUserGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
86
87
        $traceableEventDispatcher->addListener(BeforeUpdateUserGroupEventInterface::class, function (BeforeUpdateUserGroupEventInterface $event) use ($eventUpdatedUserGroup) {
88
            $event->setUpdatedUserGroup($eventUpdatedUserGroup);
89
        }, 10);
90
91
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
92
        $result = $service->updateUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserGroup() misses a required argument $userGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
93
94
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
95
96
        $this->assertSame($eventUpdatedUserGroup, $result);
97
        $this->assertSame($calledListeners, [
98
            [BeforeUpdateUserGroupEventInterface::class, 10],
99
            [BeforeUpdateUserGroupEventInterface::class, 0],
100
            [UpdateUserGroupEventInterface::class, 0],
101
        ]);
102
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
103
    }
104
105 View Code Duplication
    public function testUpdateUserGroupStopPropagationInBeforeEvents()
106
    {
107
        $traceableEventDispatcher = $this->getEventDispatcher(
108
            BeforeUpdateUserGroupEventInterface::class,
109
            UpdateUserGroupEventInterface::class
110
        );
111
112
        $parameters = [
113
            $this->createMock(UserGroup::class),
114
            $this->createMock(UserGroupUpdateStruct::class),
115
        ];
116
117
        $updatedUserGroup = $this->createMock(UserGroup::class);
118
        $eventUpdatedUserGroup = $this->createMock(UserGroup::class);
119
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
120
        $innerServiceMock->method('updateUserGroup')->willReturn($updatedUserGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
122
        $traceableEventDispatcher->addListener(BeforeUpdateUserGroupEventInterface::class, function (BeforeUpdateUserGroupEventInterface $event) use ($eventUpdatedUserGroup) {
123
            $event->setUpdatedUserGroup($eventUpdatedUserGroup);
124
            $event->stopPropagation();
125
        }, 10);
126
127
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
128
        $result = $service->updateUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserGroup() misses a required argument $userGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
129
130
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
131
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
132
133
        $this->assertSame($eventUpdatedUserGroup, $result);
134
        $this->assertSame($calledListeners, [
135
            [BeforeUpdateUserGroupEventInterface::class, 10],
136
        ]);
137
        $this->assertSame($notCalledListeners, [
138
            [BeforeUpdateUserGroupEventInterface::class, 0],
139
            [UpdateUserGroupEventInterface::class, 0],
140
        ]);
141
    }
142
143 View Code Duplication
    public function testUpdateUserEvents()
144
    {
145
        $traceableEventDispatcher = $this->getEventDispatcher(
146
            BeforeUpdateUserEventInterface::class,
147
            UpdateUserEventInterface::class
148
        );
149
150
        $parameters = [
151
            $this->createMock(User::class),
152
            $this->createMock(UserUpdateStruct::class),
153
        ];
154
155
        $updatedUser = $this->createMock(User::class);
156
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
157
        $innerServiceMock->method('updateUser')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
158
159
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
160
        $result = $service->updateUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUser() misses a required argument $userUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
161
162
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
163
164
        $this->assertSame($updatedUser, $result);
165
        $this->assertSame($calledListeners, [
166
            [BeforeUpdateUserEventInterface::class, 0],
167
            [UpdateUserEventInterface::class, 0],
168
        ]);
169
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
170
    }
171
172 View Code Duplication
    public function testReturnUpdateUserResultInBeforeEvents()
173
    {
174
        $traceableEventDispatcher = $this->getEventDispatcher(
175
            BeforeUpdateUserEventInterface::class,
176
            UpdateUserEventInterface::class
177
        );
178
179
        $parameters = [
180
            $this->createMock(User::class),
181
            $this->createMock(UserUpdateStruct::class),
182
        ];
183
184
        $updatedUser = $this->createMock(User::class);
185
        $eventUpdatedUser = $this->createMock(User::class);
186
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
187
        $innerServiceMock->method('updateUser')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
188
189
        $traceableEventDispatcher->addListener(BeforeUpdateUserEventInterface::class, function (BeforeUpdateUserEventInterface $event) use ($eventUpdatedUser) {
190
            $event->setUpdatedUser($eventUpdatedUser);
191
        }, 10);
192
193
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
194
        $result = $service->updateUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUser() misses a required argument $userUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
195
196
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
197
198
        $this->assertSame($eventUpdatedUser, $result);
199
        $this->assertSame($calledListeners, [
200
            [BeforeUpdateUserEventInterface::class, 10],
201
            [BeforeUpdateUserEventInterface::class, 0],
202
            [UpdateUserEventInterface::class, 0],
203
        ]);
204
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
205
    }
206
207 View Code Duplication
    public function testUpdateUserStopPropagationInBeforeEvents()
208
    {
209
        $traceableEventDispatcher = $this->getEventDispatcher(
210
            BeforeUpdateUserEventInterface::class,
211
            UpdateUserEventInterface::class
212
        );
213
214
        $parameters = [
215
            $this->createMock(User::class),
216
            $this->createMock(UserUpdateStruct::class),
217
        ];
218
219
        $updatedUser = $this->createMock(User::class);
220
        $eventUpdatedUser = $this->createMock(User::class);
221
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
222
        $innerServiceMock->method('updateUser')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
223
224
        $traceableEventDispatcher->addListener(BeforeUpdateUserEventInterface::class, function (BeforeUpdateUserEventInterface $event) use ($eventUpdatedUser) {
225
            $event->setUpdatedUser($eventUpdatedUser);
226
            $event->stopPropagation();
227
        }, 10);
228
229
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
230
        $result = $service->updateUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUser() misses a required argument $userUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
231
232
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
233
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
234
235
        $this->assertSame($eventUpdatedUser, $result);
236
        $this->assertSame($calledListeners, [
237
            [BeforeUpdateUserEventInterface::class, 10],
238
        ]);
239
        $this->assertSame($notCalledListeners, [
240
            [BeforeUpdateUserEventInterface::class, 0],
241
            [UpdateUserEventInterface::class, 0],
242
        ]);
243
    }
244
245
    public function testUnAssignUserFromUserGroupEvents()
246
    {
247
        $traceableEventDispatcher = $this->getEventDispatcher(
248
            BeforeUnAssignUserFromUserGroupEventInterface::class,
249
            UnAssignUserFromUserGroupEventInterface::class
250
        );
251
252
        $parameters = [
253
            $this->createMock(User::class),
254
            $this->createMock(UserGroup::class),
255
        ];
256
257
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
258
259
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
260
        $service->unAssignUserFromUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unAssignUserFromUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
261
262
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
263
264
        $this->assertSame($calledListeners, [
265
            [BeforeUnAssignUserFromUserGroupEventInterface::class, 0],
266
            [UnAssignUserFromUserGroupEventInterface::class, 0],
267
        ]);
268
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
269
    }
270
271 View Code Duplication
    public function testUnAssignUserFromUserGroupStopPropagationInBeforeEvents()
272
    {
273
        $traceableEventDispatcher = $this->getEventDispatcher(
274
            BeforeUnAssignUserFromUserGroupEventInterface::class,
275
            UnAssignUserFromUserGroupEventInterface::class
276
        );
277
278
        $parameters = [
279
            $this->createMock(User::class),
280
            $this->createMock(UserGroup::class),
281
        ];
282
283
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
284
285
        $traceableEventDispatcher->addListener(BeforeUnAssignUserFromUserGroupEventInterface::class, function (BeforeUnAssignUserFromUserGroupEventInterface $event) {
286
            $event->stopPropagation();
287
        }, 10);
288
289
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
290
        $service->unAssignUserFromUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unAssignUserFromUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
291
292
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
293
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
294
295
        $this->assertSame($calledListeners, [
296
            [BeforeUnAssignUserFromUserGroupEventInterface::class, 10],
297
        ]);
298
        $this->assertSame($notCalledListeners, [
299
            [BeforeUnAssignUserFromUserGroupEventInterface::class, 0],
300
            [UnAssignUserFromUserGroupEventInterface::class, 0],
301
        ]);
302
    }
303
304 View Code Duplication
    public function testDeleteUserGroupEvents()
305
    {
306
        $traceableEventDispatcher = $this->getEventDispatcher(
307
            BeforeDeleteUserGroupEventInterface::class,
308
            DeleteUserGroupEventInterface::class
309
        );
310
311
        $parameters = [
312
            $this->createMock(UserGroup::class),
313
        ];
314
315
        $locations = [];
316
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
317
        $innerServiceMock->method('deleteUserGroup')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
318
319
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
320
        $result = $service->deleteUserGroup(...$parameters);
321
322
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
323
324
        $this->assertSame($locations, $result);
325
        $this->assertSame($calledListeners, [
326
            [BeforeDeleteUserGroupEventInterface::class, 0],
327
            [DeleteUserGroupEventInterface::class, 0],
328
        ]);
329
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
330
    }
331
332
    public function testReturnDeleteUserGroupResultInBeforeEvents()
333
    {
334
        $traceableEventDispatcher = $this->getEventDispatcher(
335
            BeforeDeleteUserGroupEventInterface::class,
336
            DeleteUserGroupEventInterface::class
337
        );
338
339
        $parameters = [
340
            $this->createMock(UserGroup::class),
341
        ];
342
343
        $locations = [];
344
        $eventLocations = [];
345
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
346
        $innerServiceMock->method('deleteUserGroup')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
347
348
        $traceableEventDispatcher->addListener(BeforeDeleteUserGroupEventInterface::class, function (BeforeDeleteUserGroupEventInterface $event) use ($eventLocations) {
349
            $event->setLocations($eventLocations);
350
        }, 10);
351
352
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
353
        $result = $service->deleteUserGroup(...$parameters);
354
355
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
356
357
        $this->assertSame($eventLocations, $result);
358
        $this->assertSame($calledListeners, [
359
            [BeforeDeleteUserGroupEventInterface::class, 10],
360
            [BeforeDeleteUserGroupEventInterface::class, 0],
361
            [DeleteUserGroupEventInterface::class, 0],
362
        ]);
363
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
364
    }
365
366
    public function testDeleteUserGroupStopPropagationInBeforeEvents()
367
    {
368
        $traceableEventDispatcher = $this->getEventDispatcher(
369
            BeforeDeleteUserGroupEventInterface::class,
370
            DeleteUserGroupEventInterface::class
371
        );
372
373
        $parameters = [
374
            $this->createMock(UserGroup::class),
375
        ];
376
377
        $locations = [];
378
        $eventLocations = [];
379
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
380
        $innerServiceMock->method('deleteUserGroup')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
381
382
        $traceableEventDispatcher->addListener(BeforeDeleteUserGroupEventInterface::class, function (BeforeDeleteUserGroupEventInterface $event) use ($eventLocations) {
383
            $event->setLocations($eventLocations);
384
            $event->stopPropagation();
385
        }, 10);
386
387
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
388
        $result = $service->deleteUserGroup(...$parameters);
389
390
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
391
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
392
393
        $this->assertSame($eventLocations, $result);
394
        $this->assertSame($calledListeners, [
395
            [BeforeDeleteUserGroupEventInterface::class, 10],
396
        ]);
397
        $this->assertSame($notCalledListeners, [
398
            [BeforeDeleteUserGroupEventInterface::class, 0],
399
            [DeleteUserGroupEventInterface::class, 0],
400
        ]);
401
    }
402
403
    public function testAssignUserToUserGroupEvents()
404
    {
405
        $traceableEventDispatcher = $this->getEventDispatcher(
406
            BeforeAssignUserToUserGroupEventInterface::class,
407
            AssignUserToUserGroupEventInterface::class
408
        );
409
410
        $parameters = [
411
            $this->createMock(User::class),
412
            $this->createMock(UserGroup::class),
413
        ];
414
415
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
416
417
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
418
        $service->assignUserToUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignUserToUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
419
420
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
421
422
        $this->assertSame($calledListeners, [
423
            [BeforeAssignUserToUserGroupEventInterface::class, 0],
424
            [AssignUserToUserGroupEventInterface::class, 0],
425
        ]);
426
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
427
    }
428
429 View Code Duplication
    public function testAssignUserToUserGroupStopPropagationInBeforeEvents()
430
    {
431
        $traceableEventDispatcher = $this->getEventDispatcher(
432
            BeforeAssignUserToUserGroupEventInterface::class,
433
            AssignUserToUserGroupEventInterface::class
434
        );
435
436
        $parameters = [
437
            $this->createMock(User::class),
438
            $this->createMock(UserGroup::class),
439
        ];
440
441
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
442
443
        $traceableEventDispatcher->addListener(BeforeAssignUserToUserGroupEventInterface::class, function (BeforeAssignUserToUserGroupEventInterface $event) {
444
            $event->stopPropagation();
445
        }, 10);
446
447
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
448
        $service->assignUserToUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignUserToUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
449
450
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
451
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
452
453
        $this->assertSame($calledListeners, [
454
            [BeforeAssignUserToUserGroupEventInterface::class, 10],
455
        ]);
456
        $this->assertSame($notCalledListeners, [
457
            [AssignUserToUserGroupEventInterface::class, 0],
458
            [BeforeAssignUserToUserGroupEventInterface::class, 0],
459
        ]);
460
    }
461
462 View Code Duplication
    public function testDeleteUserEvents()
463
    {
464
        $traceableEventDispatcher = $this->getEventDispatcher(
465
            BeforeDeleteUserEventInterface::class,
466
            DeleteUserEventInterface::class
467
        );
468
469
        $parameters = [
470
            $this->createMock(User::class),
471
        ];
472
473
        $locations = [];
474
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
475
        $innerServiceMock->method('deleteUser')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
476
477
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
478
        $result = $service->deleteUser(...$parameters);
479
480
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
481
482
        $this->assertSame($locations, $result);
483
        $this->assertSame($calledListeners, [
484
            [BeforeDeleteUserEventInterface::class, 0],
485
            [DeleteUserEventInterface::class, 0],
486
        ]);
487
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
488
    }
489
490
    public function testReturnDeleteUserResultInBeforeEvents()
491
    {
492
        $traceableEventDispatcher = $this->getEventDispatcher(
493
            BeforeDeleteUserEventInterface::class,
494
            DeleteUserEventInterface::class
495
        );
496
497
        $parameters = [
498
            $this->createMock(User::class),
499
        ];
500
501
        $locations = [];
502
        $eventLocations = [];
503
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
504
        $innerServiceMock->method('deleteUser')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
505
506
        $traceableEventDispatcher->addListener(BeforeDeleteUserEventInterface::class, function (BeforeDeleteUserEventInterface $event) use ($eventLocations) {
507
            $event->setLocations($eventLocations);
508
        }, 10);
509
510
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
511
        $result = $service->deleteUser(...$parameters);
512
513
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
514
515
        $this->assertSame($eventLocations, $result);
516
        $this->assertSame($calledListeners, [
517
            [BeforeDeleteUserEventInterface::class, 10],
518
            [BeforeDeleteUserEventInterface::class, 0],
519
            [DeleteUserEventInterface::class, 0],
520
        ]);
521
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
522
    }
523
524
    public function testDeleteUserStopPropagationInBeforeEvents()
525
    {
526
        $traceableEventDispatcher = $this->getEventDispatcher(
527
            BeforeDeleteUserEventInterface::class,
528
            DeleteUserEventInterface::class
529
        );
530
531
        $parameters = [
532
            $this->createMock(User::class),
533
        ];
534
535
        $locations = [];
536
        $eventLocations = [];
537
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
538
        $innerServiceMock->method('deleteUser')->willReturn($locations);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
539
540
        $traceableEventDispatcher->addListener(BeforeDeleteUserEventInterface::class, function (BeforeDeleteUserEventInterface $event) use ($eventLocations) {
541
            $event->setLocations($eventLocations);
542
            $event->stopPropagation();
543
        }, 10);
544
545
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
546
        $result = $service->deleteUser(...$parameters);
547
548
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
549
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
550
551
        $this->assertSame($eventLocations, $result);
552
        $this->assertSame($calledListeners, [
553
            [BeforeDeleteUserEventInterface::class, 10],
554
        ]);
555
        $this->assertSame($notCalledListeners, [
556
            [BeforeDeleteUserEventInterface::class, 0],
557
            [DeleteUserEventInterface::class, 0],
558
        ]);
559
    }
560
561
    public function testMoveUserGroupEvents()
562
    {
563
        $traceableEventDispatcher = $this->getEventDispatcher(
564
            BeforeMoveUserGroupEventInterface::class,
565
            MoveUserGroupEventInterface::class
566
        );
567
568
        $parameters = [
569
            $this->createMock(UserGroup::class),
570
            $this->createMock(UserGroup::class),
571
        ];
572
573
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
574
575
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
576
        $service->moveUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to moveUserGroup() misses a required argument $newParent.

This check looks for function calls that miss required arguments.

Loading history...
577
578
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
579
580
        $this->assertSame($calledListeners, [
581
            [BeforeMoveUserGroupEventInterface::class, 0],
582
            [MoveUserGroupEventInterface::class, 0],
583
        ]);
584
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
585
    }
586
587 View Code Duplication
    public function testMoveUserGroupStopPropagationInBeforeEvents()
588
    {
589
        $traceableEventDispatcher = $this->getEventDispatcher(
590
            BeforeMoveUserGroupEventInterface::class,
591
            MoveUserGroupEventInterface::class
592
        );
593
594
        $parameters = [
595
            $this->createMock(UserGroup::class),
596
            $this->createMock(UserGroup::class),
597
        ];
598
599
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
600
601
        $traceableEventDispatcher->addListener(BeforeMoveUserGroupEventInterface::class, function (BeforeMoveUserGroupEventInterface $event) {
602
            $event->stopPropagation();
603
        }, 10);
604
605
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
606
        $service->moveUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to moveUserGroup() misses a required argument $newParent.

This check looks for function calls that miss required arguments.

Loading history...
607
608
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
609
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
610
611
        $this->assertSame($calledListeners, [
612
            [BeforeMoveUserGroupEventInterface::class, 10],
613
        ]);
614
        $this->assertSame($notCalledListeners, [
615
            [BeforeMoveUserGroupEventInterface::class, 0],
616
            [MoveUserGroupEventInterface::class, 0],
617
        ]);
618
    }
619
620 View Code Duplication
    public function testCreateUserEvents()
621
    {
622
        $traceableEventDispatcher = $this->getEventDispatcher(
623
            BeforeCreateUserEventInterface::class,
624
            CreateUserEventInterface::class
625
        );
626
627
        $parameters = [
628
            $this->createMock(UserCreateStruct::class),
629
            [],
630
        ];
631
632
        $user = $this->createMock(User::class);
633
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
634
        $innerServiceMock->method('createUser')->willReturn($user);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
635
636
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
637
        $result = $service->createUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUser() misses a required argument $parentGroups.

This check looks for function calls that miss required arguments.

Loading history...
638
639
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
640
641
        $this->assertSame($user, $result);
642
        $this->assertSame($calledListeners, [
643
            [BeforeCreateUserEventInterface::class, 0],
644
            [CreateUserEventInterface::class, 0],
645
        ]);
646
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
647
    }
648
649 View Code Duplication
    public function testReturnCreateUserResultInBeforeEvents()
650
    {
651
        $traceableEventDispatcher = $this->getEventDispatcher(
652
            BeforeCreateUserEventInterface::class,
653
            CreateUserEventInterface::class
654
        );
655
656
        $parameters = [
657
            $this->createMock(UserCreateStruct::class),
658
            [],
659
        ];
660
661
        $user = $this->createMock(User::class);
662
        $eventUser = $this->createMock(User::class);
663
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
664
        $innerServiceMock->method('createUser')->willReturn($user);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
665
666
        $traceableEventDispatcher->addListener(BeforeCreateUserEventInterface::class, function (BeforeCreateUserEventInterface $event) use ($eventUser) {
667
            $event->setUser($eventUser);
668
        }, 10);
669
670
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
671
        $result = $service->createUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUser() misses a required argument $parentGroups.

This check looks for function calls that miss required arguments.

Loading history...
672
673
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
674
675
        $this->assertSame($eventUser, $result);
676
        $this->assertSame($calledListeners, [
677
            [BeforeCreateUserEventInterface::class, 10],
678
            [BeforeCreateUserEventInterface::class, 0],
679
            [CreateUserEventInterface::class, 0],
680
        ]);
681
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
682
    }
683
684 View Code Duplication
    public function testCreateUserStopPropagationInBeforeEvents()
685
    {
686
        $traceableEventDispatcher = $this->getEventDispatcher(
687
            BeforeCreateUserEventInterface::class,
688
            CreateUserEventInterface::class
689
        );
690
691
        $parameters = [
692
            $this->createMock(UserCreateStruct::class),
693
            [],
694
        ];
695
696
        $user = $this->createMock(User::class);
697
        $eventUser = $this->createMock(User::class);
698
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
699
        $innerServiceMock->method('createUser')->willReturn($user);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
700
701
        $traceableEventDispatcher->addListener(BeforeCreateUserEventInterface::class, function (BeforeCreateUserEventInterface $event) use ($eventUser) {
702
            $event->setUser($eventUser);
703
            $event->stopPropagation();
704
        }, 10);
705
706
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
707
        $result = $service->createUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUser() misses a required argument $parentGroups.

This check looks for function calls that miss required arguments.

Loading history...
708
709
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
710
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
711
712
        $this->assertSame($eventUser, $result);
713
        $this->assertSame($calledListeners, [
714
            [BeforeCreateUserEventInterface::class, 10],
715
        ]);
716
        $this->assertSame($notCalledListeners, [
717
            [BeforeCreateUserEventInterface::class, 0],
718
            [CreateUserEventInterface::class, 0],
719
        ]);
720
    }
721
722 View Code Duplication
    public function testCreateUserGroupEvents()
723
    {
724
        $traceableEventDispatcher = $this->getEventDispatcher(
725
            BeforeCreateUserGroupEventInterface::class,
726
            CreateUserGroupEventInterface::class
727
        );
728
729
        $parameters = [
730
            $this->createMock(UserGroupCreateStruct::class),
731
            $this->createMock(UserGroup::class),
732
        ];
733
734
        $userGroup = $this->createMock(UserGroup::class);
735
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
736
        $innerServiceMock->method('createUserGroup')->willReturn($userGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
737
738
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
739
        $result = $service->createUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUserGroup() misses a required argument $parentGroup.

This check looks for function calls that miss required arguments.

Loading history...
740
741
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
742
743
        $this->assertSame($userGroup, $result);
744
        $this->assertSame($calledListeners, [
745
            [BeforeCreateUserGroupEventInterface::class, 0],
746
            [CreateUserGroupEventInterface::class, 0],
747
        ]);
748
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
749
    }
750
751 View Code Duplication
    public function testReturnCreateUserGroupResultInBeforeEvents()
752
    {
753
        $traceableEventDispatcher = $this->getEventDispatcher(
754
            BeforeCreateUserGroupEventInterface::class,
755
            CreateUserGroupEventInterface::class
756
        );
757
758
        $parameters = [
759
            $this->createMock(UserGroupCreateStruct::class),
760
            $this->createMock(UserGroup::class),
761
        ];
762
763
        $userGroup = $this->createMock(UserGroup::class);
764
        $eventUserGroup = $this->createMock(UserGroup::class);
765
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
766
        $innerServiceMock->method('createUserGroup')->willReturn($userGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
767
768
        $traceableEventDispatcher->addListener(BeforeCreateUserGroupEventInterface::class, function (BeforeCreateUserGroupEventInterface $event) use ($eventUserGroup) {
769
            $event->setUserGroup($eventUserGroup);
770
        }, 10);
771
772
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
773
        $result = $service->createUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUserGroup() misses a required argument $parentGroup.

This check looks for function calls that miss required arguments.

Loading history...
774
775
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
776
777
        $this->assertSame($eventUserGroup, $result);
778
        $this->assertSame($calledListeners, [
779
            [BeforeCreateUserGroupEventInterface::class, 10],
780
            [BeforeCreateUserGroupEventInterface::class, 0],
781
            [CreateUserGroupEventInterface::class, 0],
782
        ]);
783
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
784
    }
785
786 View Code Duplication
    public function testCreateUserGroupStopPropagationInBeforeEvents()
787
    {
788
        $traceableEventDispatcher = $this->getEventDispatcher(
789
            BeforeCreateUserGroupEventInterface::class,
790
            CreateUserGroupEventInterface::class
791
        );
792
793
        $parameters = [
794
            $this->createMock(UserGroupCreateStruct::class),
795
            $this->createMock(UserGroup::class),
796
        ];
797
798
        $userGroup = $this->createMock(UserGroup::class);
799
        $eventUserGroup = $this->createMock(UserGroup::class);
800
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
801
        $innerServiceMock->method('createUserGroup')->willReturn($userGroup);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
802
803
        $traceableEventDispatcher->addListener(BeforeCreateUserGroupEventInterface::class, function (BeforeCreateUserGroupEventInterface $event) use ($eventUserGroup) {
804
            $event->setUserGroup($eventUserGroup);
805
            $event->stopPropagation();
806
        }, 10);
807
808
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
809
        $result = $service->createUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createUserGroup() misses a required argument $parentGroup.

This check looks for function calls that miss required arguments.

Loading history...
810
811
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
812
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
813
814
        $this->assertSame($eventUserGroup, $result);
815
        $this->assertSame($calledListeners, [
816
            [BeforeCreateUserGroupEventInterface::class, 10],
817
        ]);
818
        $this->assertSame($notCalledListeners, [
819
            [BeforeCreateUserGroupEventInterface::class, 0],
820
            [CreateUserGroupEventInterface::class, 0],
821
        ]);
822
    }
823
824 View Code Duplication
    public function testUpdateUserTokenEvents()
825
    {
826
        $traceableEventDispatcher = $this->getEventDispatcher(
827
            BeforeUpdateUserTokenEventInterface::class,
828
            UpdateUserTokenEventInterface::class
829
        );
830
831
        $parameters = [
832
            $this->createMock(User::class),
833
            $this->createMock(UserTokenUpdateStruct::class),
834
        ];
835
836
        $updatedUser = $this->createMock(User::class);
837
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
838
        $innerServiceMock->method('updateUserToken')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
839
840
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
841
        $result = $service->updateUserToken(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserToken() misses a required argument $userTokenUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
842
843
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
844
845
        $this->assertSame($updatedUser, $result);
846
        $this->assertSame($calledListeners, [
847
            [BeforeUpdateUserTokenEventInterface::class, 0],
848
            [UpdateUserTokenEventInterface::class, 0],
849
        ]);
850
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
851
    }
852
853 View Code Duplication
    public function testReturnUpdateUserTokenResultInBeforeEvents()
854
    {
855
        $traceableEventDispatcher = $this->getEventDispatcher(
856
            BeforeUpdateUserTokenEventInterface::class,
857
            UpdateUserTokenEventInterface::class
858
        );
859
860
        $parameters = [
861
            $this->createMock(User::class),
862
            $this->createMock(UserTokenUpdateStruct::class),
863
        ];
864
865
        $updatedUser = $this->createMock(User::class);
866
        $eventUpdatedUser = $this->createMock(User::class);
867
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
868
        $innerServiceMock->method('updateUserToken')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
869
870
        $traceableEventDispatcher->addListener(BeforeUpdateUserTokenEventInterface::class, function (BeforeUpdateUserTokenEventInterface $event) use ($eventUpdatedUser) {
871
            $event->setUpdatedUser($eventUpdatedUser);
872
        }, 10);
873
874
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
875
        $result = $service->updateUserToken(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserToken() misses a required argument $userTokenUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
876
877
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
878
879
        $this->assertSame($eventUpdatedUser, $result);
880
        $this->assertSame($calledListeners, [
881
            [BeforeUpdateUserTokenEventInterface::class, 10],
882
            [BeforeUpdateUserTokenEventInterface::class, 0],
883
            [UpdateUserTokenEventInterface::class, 0],
884
        ]);
885
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
886
    }
887
888 View Code Duplication
    public function testUpdateUserTokenStopPropagationInBeforeEvents()
889
    {
890
        $traceableEventDispatcher = $this->getEventDispatcher(
891
            BeforeUpdateUserTokenEventInterface::class,
892
            UpdateUserTokenEventInterface::class
893
        );
894
895
        $parameters = [
896
            $this->createMock(User::class),
897
            $this->createMock(UserTokenUpdateStruct::class),
898
        ];
899
900
        $updatedUser = $this->createMock(User::class);
901
        $eventUpdatedUser = $this->createMock(User::class);
902
        $innerServiceMock = $this->createMock(UserServiceInterface::class);
903
        $innerServiceMock->method('updateUserToken')->willReturn($updatedUser);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
904
905
        $traceableEventDispatcher->addListener(BeforeUpdateUserTokenEventInterface::class, function (BeforeUpdateUserTokenEventInterface $event) use ($eventUpdatedUser) {
906
            $event->setUpdatedUser($eventUpdatedUser);
907
            $event->stopPropagation();
908
        }, 10);
909
910
        $service = new UserService($innerServiceMock, $traceableEventDispatcher);
911
        $result = $service->updateUserToken(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateUserToken() misses a required argument $userTokenUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
912
913
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
914
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
915
916
        $this->assertSame($eventUpdatedUser, $result);
917
        $this->assertSame($calledListeners, [
918
            [BeforeUpdateUserTokenEventInterface::class, 10],
919
        ]);
920
        $this->assertSame($notCalledListeners, [
921
            [BeforeUpdateUserTokenEventInterface::class, 0],
922
            [UpdateUserTokenEventInterface::class, 0],
923
        ]);
924
    }
925
}
926