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

testAddPolicyByRoleDraftStopPropagationInBeforeEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 37
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 37
loc 37
rs 9.328
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\Role\AddPolicyByRoleDraftEvent as AddPolicyByRoleDraftEventInterface;
10
use eZ\Publish\API\Repository\Events\Role\AddPolicyEvent as AddPolicyEventInterface;
11
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserEvent as AssignRoleToUserEventInterface;
12
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserGroupEvent as AssignRoleToUserGroupEventInterface;
13
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyByRoleDraftEvent as BeforeAddPolicyByRoleDraftEventInterface;
14
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyEvent as BeforeAddPolicyEventInterface;
15
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserEvent as BeforeAssignRoleToUserEventInterface;
16
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserGroupEvent as BeforeAssignRoleToUserGroupEventInterface;
17
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleDraftEvent as BeforeCreateRoleDraftEventInterface;
18
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleEvent as BeforeCreateRoleEventInterface;
19
use eZ\Publish\API\Repository\Events\Role\BeforeDeletePolicyEvent as BeforeDeletePolicyEventInterface;
20
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleDraftEvent as BeforeDeleteRoleDraftEventInterface;
21
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleEvent as BeforeDeleteRoleEventInterface;
22
use eZ\Publish\API\Repository\Events\Role\BeforePublishRoleDraftEvent as BeforePublishRoleDraftEventInterface;
23
use eZ\Publish\API\Repository\Events\Role\BeforeRemovePolicyByRoleDraftEvent as BeforeRemovePolicyByRoleDraftEventInterface;
24
use eZ\Publish\API\Repository\Events\Role\BeforeRemoveRoleAssignmentEvent as BeforeRemoveRoleAssignmentEventInterface;
25
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserEvent as BeforeUnassignRoleFromUserEventInterface;
26
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserGroupEvent as BeforeUnassignRoleFromUserGroupEventInterface;
27
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyByRoleDraftEvent as BeforeUpdatePolicyByRoleDraftEventInterface;
28
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyEvent as BeforeUpdatePolicyEventInterface;
29
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleDraftEvent as BeforeUpdateRoleDraftEventInterface;
30
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleEvent as BeforeUpdateRoleEventInterface;
31
use eZ\Publish\API\Repository\Events\Role\CreateRoleDraftEvent as CreateRoleDraftEventInterface;
32
use eZ\Publish\API\Repository\Events\Role\CreateRoleEvent as CreateRoleEventInterface;
33
use eZ\Publish\API\Repository\Events\Role\DeletePolicyEvent as DeletePolicyEventInterface;
34
use eZ\Publish\API\Repository\Events\Role\DeleteRoleDraftEvent as DeleteRoleDraftEventInterface;
35
use eZ\Publish\API\Repository\Events\Role\DeleteRoleEvent as DeleteRoleEventInterface;
36
use eZ\Publish\API\Repository\Events\Role\PublishRoleDraftEvent as PublishRoleDraftEventInterface;
37
use eZ\Publish\API\Repository\Events\Role\RemovePolicyByRoleDraftEvent as RemovePolicyByRoleDraftEventInterface;
38
use eZ\Publish\API\Repository\Events\Role\RemoveRoleAssignmentEvent as RemoveRoleAssignmentEventInterface;
39
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserEvent as UnassignRoleFromUserEventInterface;
40
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserGroupEvent as UnassignRoleFromUserGroupEventInterface;
41
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyByRoleDraftEvent as UpdatePolicyByRoleDraftEventInterface;
42
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyEvent as UpdatePolicyEventInterface;
43
use eZ\Publish\API\Repository\Events\Role\UpdateRoleDraftEvent as UpdateRoleDraftEventInterface;
44
use eZ\Publish\API\Repository\Events\Role\UpdateRoleEvent as UpdateRoleEventInterface;
45
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
46
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
47
use eZ\Publish\API\Repository\Values\User\Policy;
48
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
49
use eZ\Publish\API\Repository\Values\User\PolicyDraft;
50
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct;
51
use eZ\Publish\API\Repository\Values\User\Role;
52
use eZ\Publish\API\Repository\Values\User\RoleAssignment;
53
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct;
54
use eZ\Publish\API\Repository\Values\User\RoleDraft;
55
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
56
use eZ\Publish\API\Repository\Values\User\User;
57
use eZ\Publish\API\Repository\Values\User\UserGroup;
58
use eZ\Publish\Core\Event\RoleService;
59
60
class RoleServiceTest extends AbstractServiceTest
61
{
62
    public function testDeletePolicyEvents()
63
    {
64
        $traceableEventDispatcher = $this->getEventDispatcher(
65
            BeforeDeletePolicyEventInterface::class,
66
            DeletePolicyEventInterface::class
67
        );
68
69
        $parameters = [
70
            $this->createMock(Policy::class),
71
        ];
72
73
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
74
75
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
76
        $service->deletePolicy(...$parameters);
77
78
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
79
80
        $this->assertSame($calledListeners, [
81
            [BeforeDeletePolicyEventInterface::class, 0],
82
            [DeletePolicyEventInterface::class, 0],
83
        ]);
84
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
85
    }
86
87
    public function testDeletePolicyStopPropagationInBeforeEvents()
88
    {
89
        $traceableEventDispatcher = $this->getEventDispatcher(
90
            BeforeDeletePolicyEventInterface::class,
91
            DeletePolicyEventInterface::class
92
        );
93
94
        $parameters = [
95
            $this->createMock(Policy::class),
96
        ];
97
98
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
99
100
        $traceableEventDispatcher->addListener(BeforeDeletePolicyEventInterface::class, function (BeforeDeletePolicyEventInterface $event) {
101
            $event->stopPropagation();
102
        }, 10);
103
104
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
105
        $service->deletePolicy(...$parameters);
106
107
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
108
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
109
110
        $this->assertSame($calledListeners, [
111
            [BeforeDeletePolicyEventInterface::class, 10],
112
        ]);
113
        $this->assertSame($notCalledListeners, [
114
            [BeforeDeletePolicyEventInterface::class, 0],
115
            [DeletePolicyEventInterface::class, 0],
116
        ]);
117
    }
118
119 View Code Duplication
    public function testUpdateRoleEvents()
120
    {
121
        $traceableEventDispatcher = $this->getEventDispatcher(
122
            BeforeUpdateRoleEventInterface::class,
123
            UpdateRoleEventInterface::class
124
        );
125
126
        $parameters = [
127
            $this->createMock(Role::class),
128
            $this->createMock(RoleUpdateStruct::class),
129
        ];
130
131
        $updatedRole = $this->createMock(Role::class);
132
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
133
        $innerServiceMock->method('updateRole')->willReturn($updatedRole);
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...
134
135
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
136
        $result = $service->updateRole(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRole() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
137
138
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
139
140
        $this->assertSame($updatedRole, $result);
141
        $this->assertSame($calledListeners, [
142
            [BeforeUpdateRoleEventInterface::class, 0],
143
            [UpdateRoleEventInterface::class, 0],
144
        ]);
145
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
146
    }
147
148 View Code Duplication
    public function testReturnUpdateRoleResultInBeforeEvents()
149
    {
150
        $traceableEventDispatcher = $this->getEventDispatcher(
151
            BeforeUpdateRoleEventInterface::class,
152
            UpdateRoleEventInterface::class
153
        );
154
155
        $parameters = [
156
            $this->createMock(Role::class),
157
            $this->createMock(RoleUpdateStruct::class),
158
        ];
159
160
        $updatedRole = $this->createMock(Role::class);
161
        $eventUpdatedRole = $this->createMock(Role::class);
162
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
163
        $innerServiceMock->method('updateRole')->willReturn($updatedRole);
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...
164
165
        $traceableEventDispatcher->addListener(BeforeUpdateRoleEventInterface::class, function (BeforeUpdateRoleEventInterface $event) use ($eventUpdatedRole) {
166
            $event->setUpdatedRole($eventUpdatedRole);
167
        }, 10);
168
169
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
170
        $result = $service->updateRole(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRole() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
171
172
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
173
174
        $this->assertSame($eventUpdatedRole, $result);
175
        $this->assertSame($calledListeners, [
176
            [BeforeUpdateRoleEventInterface::class, 10],
177
            [BeforeUpdateRoleEventInterface::class, 0],
178
            [UpdateRoleEventInterface::class, 0],
179
        ]);
180
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
181
    }
182
183 View Code Duplication
    public function testUpdateRoleStopPropagationInBeforeEvents()
184
    {
185
        $traceableEventDispatcher = $this->getEventDispatcher(
186
            BeforeUpdateRoleEventInterface::class,
187
            UpdateRoleEventInterface::class
188
        );
189
190
        $parameters = [
191
            $this->createMock(Role::class),
192
            $this->createMock(RoleUpdateStruct::class),
193
        ];
194
195
        $updatedRole = $this->createMock(Role::class);
196
        $eventUpdatedRole = $this->createMock(Role::class);
197
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
198
        $innerServiceMock->method('updateRole')->willReturn($updatedRole);
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...
199
200
        $traceableEventDispatcher->addListener(BeforeUpdateRoleEventInterface::class, function (BeforeUpdateRoleEventInterface $event) use ($eventUpdatedRole) {
201
            $event->setUpdatedRole($eventUpdatedRole);
202
            $event->stopPropagation();
203
        }, 10);
204
205
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
206
        $result = $service->updateRole(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRole() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
207
208
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
209
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
210
211
        $this->assertSame($eventUpdatedRole, $result);
212
        $this->assertSame($calledListeners, [
213
            [BeforeUpdateRoleEventInterface::class, 10],
214
        ]);
215
        $this->assertSame($notCalledListeners, [
216
            [BeforeUpdateRoleEventInterface::class, 0],
217
            [UpdateRoleEventInterface::class, 0],
218
        ]);
219
    }
220
221
    public function testPublishRoleDraftEvents()
222
    {
223
        $traceableEventDispatcher = $this->getEventDispatcher(
224
            BeforePublishRoleDraftEventInterface::class,
225
            PublishRoleDraftEventInterface::class
226
        );
227
228
        $parameters = [
229
            $this->createMock(RoleDraft::class),
230
        ];
231
232
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
233
234
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
235
        $service->publishRoleDraft(...$parameters);
236
237
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
238
239
        $this->assertSame($calledListeners, [
240
            [BeforePublishRoleDraftEventInterface::class, 0],
241
            [PublishRoleDraftEventInterface::class, 0],
242
        ]);
243
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
244
    }
245
246
    public function testPublishRoleDraftStopPropagationInBeforeEvents()
247
    {
248
        $traceableEventDispatcher = $this->getEventDispatcher(
249
            BeforePublishRoleDraftEventInterface::class,
250
            PublishRoleDraftEventInterface::class
251
        );
252
253
        $parameters = [
254
            $this->createMock(RoleDraft::class),
255
        ];
256
257
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
258
259
        $traceableEventDispatcher->addListener(BeforePublishRoleDraftEventInterface::class, function (BeforePublishRoleDraftEventInterface $event) {
260
            $event->stopPropagation();
261
        }, 10);
262
263
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
264
        $service->publishRoleDraft(...$parameters);
265
266
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
267
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
268
269
        $this->assertSame($calledListeners, [
270
            [BeforePublishRoleDraftEventInterface::class, 10],
271
        ]);
272
        $this->assertSame($notCalledListeners, [
273
            [BeforePublishRoleDraftEventInterface::class, 0],
274
            [PublishRoleDraftEventInterface::class, 0],
275
        ]);
276
    }
277
278 View Code Duplication
    public function testAssignRoleToUserEvents()
279
    {
280
        $traceableEventDispatcher = $this->getEventDispatcher(
281
            BeforeAssignRoleToUserEventInterface::class,
282
            AssignRoleToUserEventInterface::class
283
        );
284
285
        $parameters = [
286
            $this->createMock(Role::class),
287
            $this->createMock(User::class),
288
            $this->createMock(RoleLimitation::class),
289
        ];
290
291
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
292
293
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
294
        $service->assignRoleToUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignRoleToUser() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
295
296
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
297
298
        $this->assertSame($calledListeners, [
299
            [BeforeAssignRoleToUserEventInterface::class, 0],
300
            [AssignRoleToUserEventInterface::class, 0],
301
        ]);
302
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
303
    }
304
305 View Code Duplication
    public function testAssignRoleToUserStopPropagationInBeforeEvents()
306
    {
307
        $traceableEventDispatcher = $this->getEventDispatcher(
308
            BeforeAssignRoleToUserEventInterface::class,
309
            AssignRoleToUserEventInterface::class
310
        );
311
312
        $parameters = [
313
            $this->createMock(Role::class),
314
            $this->createMock(User::class),
315
            $this->createMock(RoleLimitation::class),
316
        ];
317
318
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
319
320
        $traceableEventDispatcher->addListener(BeforeAssignRoleToUserEventInterface::class, function (BeforeAssignRoleToUserEventInterface $event) {
321
            $event->stopPropagation();
322
        }, 10);
323
324
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
325
        $service->assignRoleToUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignRoleToUser() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
326
327
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
328
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
329
330
        $this->assertSame($calledListeners, [
331
            [BeforeAssignRoleToUserEventInterface::class, 10],
332
        ]);
333
        $this->assertSame($notCalledListeners, [
334
            [AssignRoleToUserEventInterface::class, 0],
335
            [BeforeAssignRoleToUserEventInterface::class, 0],
336
        ]);
337
    }
338
339 View Code Duplication
    public function testAddPolicyEvents()
340
    {
341
        $traceableEventDispatcher = $this->getEventDispatcher(
342
            BeforeAddPolicyEventInterface::class,
343
            AddPolicyEventInterface::class
344
        );
345
346
        $parameters = [
347
            $this->createMock(Role::class),
348
            $this->createMock(PolicyCreateStruct::class),
349
        ];
350
351
        $updatedRole = $this->createMock(Role::class);
352
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
353
        $innerServiceMock->method('addPolicy')->willReturn($updatedRole);
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...
354
355
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
356
        $result = $service->addPolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicy() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
357
358
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
359
360
        $this->assertSame($updatedRole, $result);
361
        $this->assertSame($calledListeners, [
362
            [BeforeAddPolicyEventInterface::class, 0],
363
            [AddPolicyEventInterface::class, 0],
364
        ]);
365
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
366
    }
367
368 View Code Duplication
    public function testReturnAddPolicyResultInBeforeEvents()
369
    {
370
        $traceableEventDispatcher = $this->getEventDispatcher(
371
            BeforeAddPolicyEventInterface::class,
372
            AddPolicyEventInterface::class
373
        );
374
375
        $parameters = [
376
            $this->createMock(Role::class),
377
            $this->createMock(PolicyCreateStruct::class),
378
        ];
379
380
        $updatedRole = $this->createMock(Role::class);
381
        $eventUpdatedRole = $this->createMock(Role::class);
382
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
383
        $innerServiceMock->method('addPolicy')->willReturn($updatedRole);
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...
384
385
        $traceableEventDispatcher->addListener(BeforeAddPolicyEventInterface::class, function (BeforeAddPolicyEventInterface $event) use ($eventUpdatedRole) {
386
            $event->setUpdatedRole($eventUpdatedRole);
387
        }, 10);
388
389
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
390
        $result = $service->addPolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicy() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
391
392
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
393
394
        $this->assertSame($eventUpdatedRole, $result);
395
        $this->assertSame($calledListeners, [
396
            [BeforeAddPolicyEventInterface::class, 10],
397
            [BeforeAddPolicyEventInterface::class, 0],
398
            [AddPolicyEventInterface::class, 0],
399
        ]);
400
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
401
    }
402
403 View Code Duplication
    public function testAddPolicyStopPropagationInBeforeEvents()
404
    {
405
        $traceableEventDispatcher = $this->getEventDispatcher(
406
            BeforeAddPolicyEventInterface::class,
407
            AddPolicyEventInterface::class
408
        );
409
410
        $parameters = [
411
            $this->createMock(Role::class),
412
            $this->createMock(PolicyCreateStruct::class),
413
        ];
414
415
        $updatedRole = $this->createMock(Role::class);
416
        $eventUpdatedRole = $this->createMock(Role::class);
417
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
418
        $innerServiceMock->method('addPolicy')->willReturn($updatedRole);
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...
419
420
        $traceableEventDispatcher->addListener(BeforeAddPolicyEventInterface::class, function (BeforeAddPolicyEventInterface $event) use ($eventUpdatedRole) {
421
            $event->setUpdatedRole($eventUpdatedRole);
422
            $event->stopPropagation();
423
        }, 10);
424
425
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
426
        $result = $service->addPolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicy() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
427
428
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
429
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
430
431
        $this->assertSame($eventUpdatedRole, $result);
432
        $this->assertSame($calledListeners, [
433
            [BeforeAddPolicyEventInterface::class, 10],
434
        ]);
435
        $this->assertSame($notCalledListeners, [
436
            [AddPolicyEventInterface::class, 0],
437
            [BeforeAddPolicyEventInterface::class, 0],
438
        ]);
439
    }
440
441 View Code Duplication
    public function testUpdateRoleDraftEvents()
442
    {
443
        $traceableEventDispatcher = $this->getEventDispatcher(
444
            BeforeUpdateRoleDraftEventInterface::class,
445
            UpdateRoleDraftEventInterface::class
446
        );
447
448
        $parameters = [
449
            $this->createMock(RoleDraft::class),
450
            $this->createMock(RoleUpdateStruct::class),
451
        ];
452
453
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
454
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
455
        $innerServiceMock->method('updateRoleDraft')->willReturn($updatedRoleDraft);
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...
456
457
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
458
        $result = $service->updateRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRoleDraft() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
459
460
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
461
462
        $this->assertSame($updatedRoleDraft, $result);
463
        $this->assertSame($calledListeners, [
464
            [BeforeUpdateRoleDraftEventInterface::class, 0],
465
            [UpdateRoleDraftEventInterface::class, 0],
466
        ]);
467
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
468
    }
469
470 View Code Duplication
    public function testReturnUpdateRoleDraftResultInBeforeEvents()
471
    {
472
        $traceableEventDispatcher = $this->getEventDispatcher(
473
            BeforeUpdateRoleDraftEventInterface::class,
474
            UpdateRoleDraftEventInterface::class
475
        );
476
477
        $parameters = [
478
            $this->createMock(RoleDraft::class),
479
            $this->createMock(RoleUpdateStruct::class),
480
        ];
481
482
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
483
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
484
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
485
        $innerServiceMock->method('updateRoleDraft')->willReturn($updatedRoleDraft);
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...
486
487
        $traceableEventDispatcher->addListener(BeforeUpdateRoleDraftEventInterface::class, function (BeforeUpdateRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
488
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
489
        }, 10);
490
491
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
492
        $result = $service->updateRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRoleDraft() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
493
494
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
495
496
        $this->assertSame($eventUpdatedRoleDraft, $result);
497
        $this->assertSame($calledListeners, [
498
            [BeforeUpdateRoleDraftEventInterface::class, 10],
499
            [BeforeUpdateRoleDraftEventInterface::class, 0],
500
            [UpdateRoleDraftEventInterface::class, 0],
501
        ]);
502
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
503
    }
504
505 View Code Duplication
    public function testUpdateRoleDraftStopPropagationInBeforeEvents()
506
    {
507
        $traceableEventDispatcher = $this->getEventDispatcher(
508
            BeforeUpdateRoleDraftEventInterface::class,
509
            UpdateRoleDraftEventInterface::class
510
        );
511
512
        $parameters = [
513
            $this->createMock(RoleDraft::class),
514
            $this->createMock(RoleUpdateStruct::class),
515
        ];
516
517
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
518
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
519
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
520
        $innerServiceMock->method('updateRoleDraft')->willReturn($updatedRoleDraft);
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...
521
522
        $traceableEventDispatcher->addListener(BeforeUpdateRoleDraftEventInterface::class, function (BeforeUpdateRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
523
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
524
            $event->stopPropagation();
525
        }, 10);
526
527
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
528
        $result = $service->updateRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateRoleDraft() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
529
530
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
531
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
532
533
        $this->assertSame($eventUpdatedRoleDraft, $result);
534
        $this->assertSame($calledListeners, [
535
            [BeforeUpdateRoleDraftEventInterface::class, 10],
536
        ]);
537
        $this->assertSame($notCalledListeners, [
538
            [BeforeUpdateRoleDraftEventInterface::class, 0],
539
            [UpdateRoleDraftEventInterface::class, 0],
540
        ]);
541
    }
542
543 View Code Duplication
    public function testAssignRoleToUserGroupEvents()
544
    {
545
        $traceableEventDispatcher = $this->getEventDispatcher(
546
            BeforeAssignRoleToUserGroupEventInterface::class,
547
            AssignRoleToUserGroupEventInterface::class
548
        );
549
550
        $parameters = [
551
            $this->createMock(Role::class),
552
            $this->createMock(UserGroup::class),
553
            $this->createMock(RoleLimitation::class),
554
        ];
555
556
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
557
558
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
559
        $service->assignRoleToUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignRoleToUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
560
561
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
562
563
        $this->assertSame($calledListeners, [
564
            [BeforeAssignRoleToUserGroupEventInterface::class, 0],
565
            [AssignRoleToUserGroupEventInterface::class, 0],
566
        ]);
567
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
568
    }
569
570 View Code Duplication
    public function testAssignRoleToUserGroupStopPropagationInBeforeEvents()
571
    {
572
        $traceableEventDispatcher = $this->getEventDispatcher(
573
            BeforeAssignRoleToUserGroupEventInterface::class,
574
            AssignRoleToUserGroupEventInterface::class
575
        );
576
577
        $parameters = [
578
            $this->createMock(Role::class),
579
            $this->createMock(UserGroup::class),
580
            $this->createMock(RoleLimitation::class),
581
        ];
582
583
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
584
585
        $traceableEventDispatcher->addListener(BeforeAssignRoleToUserGroupEventInterface::class, function (BeforeAssignRoleToUserGroupEventInterface $event) {
586
            $event->stopPropagation();
587
        }, 10);
588
589
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
590
        $service->assignRoleToUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignRoleToUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
591
592
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
593
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
594
595
        $this->assertSame($calledListeners, [
596
            [BeforeAssignRoleToUserGroupEventInterface::class, 10],
597
        ]);
598
        $this->assertSame($notCalledListeners, [
599
            [AssignRoleToUserGroupEventInterface::class, 0],
600
            [BeforeAssignRoleToUserGroupEventInterface::class, 0],
601
        ]);
602
    }
603
604
    public function testUnassignRoleFromUserEvents()
605
    {
606
        $traceableEventDispatcher = $this->getEventDispatcher(
607
            BeforeUnassignRoleFromUserEventInterface::class,
608
            UnassignRoleFromUserEventInterface::class
609
        );
610
611
        $parameters = [
612
            $this->createMock(Role::class),
613
            $this->createMock(User::class),
614
        ];
615
616
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
617
618
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
619
        $service->unassignRoleFromUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unassignRoleFromUser() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
620
621
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
622
623
        $this->assertSame($calledListeners, [
624
            [BeforeUnassignRoleFromUserEventInterface::class, 0],
625
            [UnassignRoleFromUserEventInterface::class, 0],
626
        ]);
627
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
628
    }
629
630 View Code Duplication
    public function testUnassignRoleFromUserStopPropagationInBeforeEvents()
631
    {
632
        $traceableEventDispatcher = $this->getEventDispatcher(
633
            BeforeUnassignRoleFromUserEventInterface::class,
634
            UnassignRoleFromUserEventInterface::class
635
        );
636
637
        $parameters = [
638
            $this->createMock(Role::class),
639
            $this->createMock(User::class),
640
        ];
641
642
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
643
644
        $traceableEventDispatcher->addListener(BeforeUnassignRoleFromUserEventInterface::class, function (BeforeUnassignRoleFromUserEventInterface $event) {
645
            $event->stopPropagation();
646
        }, 10);
647
648
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
649
        $service->unassignRoleFromUser(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unassignRoleFromUser() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
650
651
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
652
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
653
654
        $this->assertSame($calledListeners, [
655
            [BeforeUnassignRoleFromUserEventInterface::class, 10],
656
        ]);
657
        $this->assertSame($notCalledListeners, [
658
            [BeforeUnassignRoleFromUserEventInterface::class, 0],
659
            [UnassignRoleFromUserEventInterface::class, 0],
660
        ]);
661
    }
662
663 View Code Duplication
    public function testUpdatePolicyByRoleDraftEvents()
664
    {
665
        $traceableEventDispatcher = $this->getEventDispatcher(
666
            BeforeUpdatePolicyByRoleDraftEventInterface::class,
667
            UpdatePolicyByRoleDraftEventInterface::class
668
        );
669
670
        $parameters = [
671
            $this->createMock(RoleDraft::class),
672
            $this->createMock(PolicyDraft::class),
673
            $this->createMock(PolicyUpdateStruct::class),
674
        ];
675
676
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
677
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
678
        $innerServiceMock->method('updatePolicyByRoleDraft')->willReturn($updatedPolicyDraft);
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...
679
680
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
681
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
682
683
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
684
685
        $this->assertSame($updatedPolicyDraft, $result);
686
        $this->assertSame($calledListeners, [
687
            [BeforeUpdatePolicyByRoleDraftEventInterface::class, 0],
688
            [UpdatePolicyByRoleDraftEventInterface::class, 0],
689
        ]);
690
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
691
    }
692
693
    public function testReturnUpdatePolicyByRoleDraftResultInBeforeEvents()
694
    {
695
        $traceableEventDispatcher = $this->getEventDispatcher(
696
            BeforeUpdatePolicyByRoleDraftEventInterface::class,
697
            UpdatePolicyByRoleDraftEventInterface::class
698
        );
699
700
        $parameters = [
701
            $this->createMock(RoleDraft::class),
702
            $this->createMock(PolicyDraft::class),
703
            $this->createMock(PolicyUpdateStruct::class),
704
        ];
705
706
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
707
        $eventUpdatedPolicyDraft = $this->createMock(PolicyDraft::class);
708
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
709
        $innerServiceMock->method('updatePolicyByRoleDraft')->willReturn($updatedPolicyDraft);
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...
710
711
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyByRoleDraftEventInterface::class, function (BeforeUpdatePolicyByRoleDraftEventInterface $event) use ($eventUpdatedPolicyDraft) {
712
            $event->setUpdatedPolicyDraft($eventUpdatedPolicyDraft);
713
        }, 10);
714
715
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
716
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
717
718
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
719
720
        $this->assertSame($eventUpdatedPolicyDraft, $result);
721
        $this->assertSame($calledListeners, [
722
            [BeforeUpdatePolicyByRoleDraftEventInterface::class, 10],
723
            [BeforeUpdatePolicyByRoleDraftEventInterface::class, 0],
724
            [UpdatePolicyByRoleDraftEventInterface::class, 0],
725
        ]);
726
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
727
    }
728
729
    public function testUpdatePolicyByRoleDraftStopPropagationInBeforeEvents()
730
    {
731
        $traceableEventDispatcher = $this->getEventDispatcher(
732
            BeforeUpdatePolicyByRoleDraftEventInterface::class,
733
            UpdatePolicyByRoleDraftEventInterface::class
734
        );
735
736
        $parameters = [
737
            $this->createMock(RoleDraft::class),
738
            $this->createMock(PolicyDraft::class),
739
            $this->createMock(PolicyUpdateStruct::class),
740
        ];
741
742
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
743
        $eventUpdatedPolicyDraft = $this->createMock(PolicyDraft::class);
744
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
745
        $innerServiceMock->method('updatePolicyByRoleDraft')->willReturn($updatedPolicyDraft);
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...
746
747
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyByRoleDraftEventInterface::class, function (BeforeUpdatePolicyByRoleDraftEventInterface $event) use ($eventUpdatedPolicyDraft) {
748
            $event->setUpdatedPolicyDraft($eventUpdatedPolicyDraft);
749
            $event->stopPropagation();
750
        }, 10);
751
752
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
753
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
754
755
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
756
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
757
758
        $this->assertSame($eventUpdatedPolicyDraft, $result);
759
        $this->assertSame($calledListeners, [
760
            [BeforeUpdatePolicyByRoleDraftEventInterface::class, 10],
761
        ]);
762
        $this->assertSame($notCalledListeners, [
763
            [BeforeUpdatePolicyByRoleDraftEventInterface::class, 0],
764
            [UpdatePolicyByRoleDraftEventInterface::class, 0],
765
        ]);
766
    }
767
768 View Code Duplication
    public function testCreateRoleEvents()
769
    {
770
        $traceableEventDispatcher = $this->getEventDispatcher(
771
            BeforeCreateRoleEventInterface::class,
772
            CreateRoleEventInterface::class
773
        );
774
775
        $parameters = [
776
            $this->createMock(RoleCreateStruct::class),
777
        ];
778
779
        $roleDraft = $this->createMock(RoleDraft::class);
780
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
781
        $innerServiceMock->method('createRole')->willReturn($roleDraft);
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...
782
783
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
784
        $result = $service->createRole(...$parameters);
785
786
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
787
788
        $this->assertSame($roleDraft, $result);
789
        $this->assertSame($calledListeners, [
790
            [BeforeCreateRoleEventInterface::class, 0],
791
            [CreateRoleEventInterface::class, 0],
792
        ]);
793
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
794
    }
795
796 View Code Duplication
    public function testReturnCreateRoleResultInBeforeEvents()
797
    {
798
        $traceableEventDispatcher = $this->getEventDispatcher(
799
            BeforeCreateRoleEventInterface::class,
800
            CreateRoleEventInterface::class
801
        );
802
803
        $parameters = [
804
            $this->createMock(RoleCreateStruct::class),
805
        ];
806
807
        $roleDraft = $this->createMock(RoleDraft::class);
808
        $eventRoleDraft = $this->createMock(RoleDraft::class);
809
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
810
        $innerServiceMock->method('createRole')->willReturn($roleDraft);
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...
811
812
        $traceableEventDispatcher->addListener(BeforeCreateRoleEventInterface::class, function (BeforeCreateRoleEventInterface $event) use ($eventRoleDraft) {
813
            $event->setRoleDraft($eventRoleDraft);
814
        }, 10);
815
816
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
817
        $result = $service->createRole(...$parameters);
818
819
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
820
821
        $this->assertSame($eventRoleDraft, $result);
822
        $this->assertSame($calledListeners, [
823
            [BeforeCreateRoleEventInterface::class, 10],
824
            [BeforeCreateRoleEventInterface::class, 0],
825
            [CreateRoleEventInterface::class, 0],
826
        ]);
827
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
828
    }
829
830 View Code Duplication
    public function testCreateRoleStopPropagationInBeforeEvents()
831
    {
832
        $traceableEventDispatcher = $this->getEventDispatcher(
833
            BeforeCreateRoleEventInterface::class,
834
            CreateRoleEventInterface::class
835
        );
836
837
        $parameters = [
838
            $this->createMock(RoleCreateStruct::class),
839
        ];
840
841
        $roleDraft = $this->createMock(RoleDraft::class);
842
        $eventRoleDraft = $this->createMock(RoleDraft::class);
843
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
844
        $innerServiceMock->method('createRole')->willReturn($roleDraft);
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...
845
846
        $traceableEventDispatcher->addListener(BeforeCreateRoleEventInterface::class, function (BeforeCreateRoleEventInterface $event) use ($eventRoleDraft) {
847
            $event->setRoleDraft($eventRoleDraft);
848
            $event->stopPropagation();
849
        }, 10);
850
851
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
852
        $result = $service->createRole(...$parameters);
853
854
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
855
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
856
857
        $this->assertSame($eventRoleDraft, $result);
858
        $this->assertSame($calledListeners, [
859
            [BeforeCreateRoleEventInterface::class, 10],
860
        ]);
861
        $this->assertSame($notCalledListeners, [
862
            [BeforeCreateRoleEventInterface::class, 0],
863
            [CreateRoleEventInterface::class, 0],
864
        ]);
865
    }
866
867 View Code Duplication
    public function testRemovePolicyByRoleDraftEvents()
868
    {
869
        $traceableEventDispatcher = $this->getEventDispatcher(
870
            BeforeRemovePolicyByRoleDraftEventInterface::class,
871
            RemovePolicyByRoleDraftEventInterface::class
872
        );
873
874
        $parameters = [
875
            $this->createMock(RoleDraft::class),
876
            $this->createMock(PolicyDraft::class),
877
        ];
878
879
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
880
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
881
        $innerServiceMock->method('removePolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
882
883
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
884
        $result = $service->removePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to removePolicyByRoleDraft() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
885
886
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
887
888
        $this->assertSame($updatedRoleDraft, $result);
889
        $this->assertSame($calledListeners, [
890
            [BeforeRemovePolicyByRoleDraftEventInterface::class, 0],
891
            [RemovePolicyByRoleDraftEventInterface::class, 0],
892
        ]);
893
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
894
    }
895
896 View Code Duplication
    public function testReturnRemovePolicyByRoleDraftResultInBeforeEvents()
897
    {
898
        $traceableEventDispatcher = $this->getEventDispatcher(
899
            BeforeRemovePolicyByRoleDraftEventInterface::class,
900
            RemovePolicyByRoleDraftEventInterface::class
901
        );
902
903
        $parameters = [
904
            $this->createMock(RoleDraft::class),
905
            $this->createMock(PolicyDraft::class),
906
        ];
907
908
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
909
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
910
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
911
        $innerServiceMock->method('removePolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
912
913
        $traceableEventDispatcher->addListener(BeforeRemovePolicyByRoleDraftEventInterface::class, function (BeforeRemovePolicyByRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
914
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
915
        }, 10);
916
917
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
918
        $result = $service->removePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to removePolicyByRoleDraft() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
919
920
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
921
922
        $this->assertSame($eventUpdatedRoleDraft, $result);
923
        $this->assertSame($calledListeners, [
924
            [BeforeRemovePolicyByRoleDraftEventInterface::class, 10],
925
            [BeforeRemovePolicyByRoleDraftEventInterface::class, 0],
926
            [RemovePolicyByRoleDraftEventInterface::class, 0],
927
        ]);
928
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
929
    }
930
931 View Code Duplication
    public function testRemovePolicyByRoleDraftStopPropagationInBeforeEvents()
932
    {
933
        $traceableEventDispatcher = $this->getEventDispatcher(
934
            BeforeRemovePolicyByRoleDraftEventInterface::class,
935
            RemovePolicyByRoleDraftEventInterface::class
936
        );
937
938
        $parameters = [
939
            $this->createMock(RoleDraft::class),
940
            $this->createMock(PolicyDraft::class),
941
        ];
942
943
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
944
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
945
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
946
        $innerServiceMock->method('removePolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
947
948
        $traceableEventDispatcher->addListener(BeforeRemovePolicyByRoleDraftEventInterface::class, function (BeforeRemovePolicyByRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
949
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
950
            $event->stopPropagation();
951
        }, 10);
952
953
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
954
        $result = $service->removePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to removePolicyByRoleDraft() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
955
956
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
957
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
958
959
        $this->assertSame($eventUpdatedRoleDraft, $result);
960
        $this->assertSame($calledListeners, [
961
            [BeforeRemovePolicyByRoleDraftEventInterface::class, 10],
962
        ]);
963
        $this->assertSame($notCalledListeners, [
964
            [BeforeRemovePolicyByRoleDraftEventInterface::class, 0],
965
            [RemovePolicyByRoleDraftEventInterface::class, 0],
966
        ]);
967
    }
968
969 View Code Duplication
    public function testAddPolicyByRoleDraftEvents()
970
    {
971
        $traceableEventDispatcher = $this->getEventDispatcher(
972
            BeforeAddPolicyByRoleDraftEventInterface::class,
973
            AddPolicyByRoleDraftEventInterface::class
974
        );
975
976
        $parameters = [
977
            $this->createMock(RoleDraft::class),
978
            $this->createMock(PolicyCreateStruct::class),
979
        ];
980
981
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
982
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
983
        $innerServiceMock->method('addPolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
984
985
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
986
        $result = $service->addPolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicyByRoleDraft() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
987
988
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
989
990
        $this->assertSame($updatedRoleDraft, $result);
991
        $this->assertSame($calledListeners, [
992
            [BeforeAddPolicyByRoleDraftEventInterface::class, 0],
993
            [AddPolicyByRoleDraftEventInterface::class, 0],
994
        ]);
995
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
996
    }
997
998 View Code Duplication
    public function testReturnAddPolicyByRoleDraftResultInBeforeEvents()
999
    {
1000
        $traceableEventDispatcher = $this->getEventDispatcher(
1001
            BeforeAddPolicyByRoleDraftEventInterface::class,
1002
            AddPolicyByRoleDraftEventInterface::class
1003
        );
1004
1005
        $parameters = [
1006
            $this->createMock(RoleDraft::class),
1007
            $this->createMock(PolicyCreateStruct::class),
1008
        ];
1009
1010
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
1011
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
1012
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1013
        $innerServiceMock->method('addPolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
1014
1015
        $traceableEventDispatcher->addListener(BeforeAddPolicyByRoleDraftEventInterface::class, function (BeforeAddPolicyByRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
1016
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
1017
        }, 10);
1018
1019
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1020
        $result = $service->addPolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicyByRoleDraft() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
1021
1022
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1023
1024
        $this->assertSame($eventUpdatedRoleDraft, $result);
1025
        $this->assertSame($calledListeners, [
1026
            [BeforeAddPolicyByRoleDraftEventInterface::class, 10],
1027
            [BeforeAddPolicyByRoleDraftEventInterface::class, 0],
1028
            [AddPolicyByRoleDraftEventInterface::class, 0],
1029
        ]);
1030
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1031
    }
1032
1033 View Code Duplication
    public function testAddPolicyByRoleDraftStopPropagationInBeforeEvents()
1034
    {
1035
        $traceableEventDispatcher = $this->getEventDispatcher(
1036
            BeforeAddPolicyByRoleDraftEventInterface::class,
1037
            AddPolicyByRoleDraftEventInterface::class
1038
        );
1039
1040
        $parameters = [
1041
            $this->createMock(RoleDraft::class),
1042
            $this->createMock(PolicyCreateStruct::class),
1043
        ];
1044
1045
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
1046
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
1047
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1048
        $innerServiceMock->method('addPolicyByRoleDraft')->willReturn($updatedRoleDraft);
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...
1049
1050
        $traceableEventDispatcher->addListener(BeforeAddPolicyByRoleDraftEventInterface::class, function (BeforeAddPolicyByRoleDraftEventInterface $event) use ($eventUpdatedRoleDraft) {
1051
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
1052
            $event->stopPropagation();
1053
        }, 10);
1054
1055
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1056
        $result = $service->addPolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addPolicyByRoleDraft() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
1057
1058
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1059
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1060
1061
        $this->assertSame($eventUpdatedRoleDraft, $result);
1062
        $this->assertSame($calledListeners, [
1063
            [BeforeAddPolicyByRoleDraftEventInterface::class, 10],
1064
        ]);
1065
        $this->assertSame($notCalledListeners, [
1066
            [AddPolicyByRoleDraftEventInterface::class, 0],
1067
            [BeforeAddPolicyByRoleDraftEventInterface::class, 0],
1068
        ]);
1069
    }
1070
1071
    public function testDeleteRoleEvents()
1072
    {
1073
        $traceableEventDispatcher = $this->getEventDispatcher(
1074
            BeforeDeleteRoleEventInterface::class,
1075
            DeleteRoleEventInterface::class
1076
        );
1077
1078
        $parameters = [
1079
            $this->createMock(Role::class),
1080
        ];
1081
1082
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1083
1084
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1085
        $service->deleteRole(...$parameters);
1086
1087
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1088
1089
        $this->assertSame($calledListeners, [
1090
            [BeforeDeleteRoleEventInterface::class, 0],
1091
            [DeleteRoleEventInterface::class, 0],
1092
        ]);
1093
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1094
    }
1095
1096
    public function testDeleteRoleStopPropagationInBeforeEvents()
1097
    {
1098
        $traceableEventDispatcher = $this->getEventDispatcher(
1099
            BeforeDeleteRoleEventInterface::class,
1100
            DeleteRoleEventInterface::class
1101
        );
1102
1103
        $parameters = [
1104
            $this->createMock(Role::class),
1105
        ];
1106
1107
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1108
1109
        $traceableEventDispatcher->addListener(BeforeDeleteRoleEventInterface::class, function (BeforeDeleteRoleEventInterface $event) {
1110
            $event->stopPropagation();
1111
        }, 10);
1112
1113
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1114
        $service->deleteRole(...$parameters);
1115
1116
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1117
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1118
1119
        $this->assertSame($calledListeners, [
1120
            [BeforeDeleteRoleEventInterface::class, 10],
1121
        ]);
1122
        $this->assertSame($notCalledListeners, [
1123
            [BeforeDeleteRoleEventInterface::class, 0],
1124
            [DeleteRoleEventInterface::class, 0],
1125
        ]);
1126
    }
1127
1128
    public function testDeleteRoleDraftEvents()
1129
    {
1130
        $traceableEventDispatcher = $this->getEventDispatcher(
1131
            BeforeDeleteRoleDraftEventInterface::class,
1132
            DeleteRoleDraftEventInterface::class
1133
        );
1134
1135
        $parameters = [
1136
            $this->createMock(RoleDraft::class),
1137
        ];
1138
1139
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1140
1141
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1142
        $service->deleteRoleDraft(...$parameters);
1143
1144
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1145
1146
        $this->assertSame($calledListeners, [
1147
            [BeforeDeleteRoleDraftEventInterface::class, 0],
1148
            [DeleteRoleDraftEventInterface::class, 0],
1149
        ]);
1150
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1151
    }
1152
1153
    public function testDeleteRoleDraftStopPropagationInBeforeEvents()
1154
    {
1155
        $traceableEventDispatcher = $this->getEventDispatcher(
1156
            BeforeDeleteRoleDraftEventInterface::class,
1157
            DeleteRoleDraftEventInterface::class
1158
        );
1159
1160
        $parameters = [
1161
            $this->createMock(RoleDraft::class),
1162
        ];
1163
1164
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1165
1166
        $traceableEventDispatcher->addListener(BeforeDeleteRoleDraftEventInterface::class, function (BeforeDeleteRoleDraftEventInterface $event) {
1167
            $event->stopPropagation();
1168
        }, 10);
1169
1170
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1171
        $service->deleteRoleDraft(...$parameters);
1172
1173
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1174
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1175
1176
        $this->assertSame($calledListeners, [
1177
            [BeforeDeleteRoleDraftEventInterface::class, 10],
1178
        ]);
1179
        $this->assertSame($notCalledListeners, [
1180
            [BeforeDeleteRoleDraftEventInterface::class, 0],
1181
            [DeleteRoleDraftEventInterface::class, 0],
1182
        ]);
1183
    }
1184
1185
    public function testRemoveRoleAssignmentEvents()
1186
    {
1187
        $traceableEventDispatcher = $this->getEventDispatcher(
1188
            BeforeRemoveRoleAssignmentEventInterface::class,
1189
            RemoveRoleAssignmentEventInterface::class
1190
        );
1191
1192
        $parameters = [
1193
            $this->createMock(RoleAssignment::class),
1194
        ];
1195
1196
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1197
1198
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1199
        $service->removeRoleAssignment(...$parameters);
1200
1201
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1202
1203
        $this->assertSame($calledListeners, [
1204
            [BeforeRemoveRoleAssignmentEventInterface::class, 0],
1205
            [RemoveRoleAssignmentEventInterface::class, 0],
1206
        ]);
1207
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1208
    }
1209
1210
    public function testRemoveRoleAssignmentStopPropagationInBeforeEvents()
1211
    {
1212
        $traceableEventDispatcher = $this->getEventDispatcher(
1213
            BeforeRemoveRoleAssignmentEventInterface::class,
1214
            RemoveRoleAssignmentEventInterface::class
1215
        );
1216
1217
        $parameters = [
1218
            $this->createMock(RoleAssignment::class),
1219
        ];
1220
1221
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1222
1223
        $traceableEventDispatcher->addListener(BeforeRemoveRoleAssignmentEventInterface::class, function (BeforeRemoveRoleAssignmentEventInterface $event) {
1224
            $event->stopPropagation();
1225
        }, 10);
1226
1227
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1228
        $service->removeRoleAssignment(...$parameters);
1229
1230
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1231
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1232
1233
        $this->assertSame($calledListeners, [
1234
            [BeforeRemoveRoleAssignmentEventInterface::class, 10],
1235
        ]);
1236
        $this->assertSame($notCalledListeners, [
1237
            [BeforeRemoveRoleAssignmentEventInterface::class, 0],
1238
            [RemoveRoleAssignmentEventInterface::class, 0],
1239
        ]);
1240
    }
1241
1242 View Code Duplication
    public function testCreateRoleDraftEvents()
1243
    {
1244
        $traceableEventDispatcher = $this->getEventDispatcher(
1245
            BeforeCreateRoleDraftEventInterface::class,
1246
            CreateRoleDraftEventInterface::class
1247
        );
1248
1249
        $parameters = [
1250
            $this->createMock(Role::class),
1251
        ];
1252
1253
        $roleDraft = $this->createMock(RoleDraft::class);
1254
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1255
        $innerServiceMock->method('createRoleDraft')->willReturn($roleDraft);
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...
1256
1257
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1258
        $result = $service->createRoleDraft(...$parameters);
1259
1260
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1261
1262
        $this->assertSame($roleDraft, $result);
1263
        $this->assertSame($calledListeners, [
1264
            [BeforeCreateRoleDraftEventInterface::class, 0],
1265
            [CreateRoleDraftEventInterface::class, 0],
1266
        ]);
1267
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1268
    }
1269
1270 View Code Duplication
    public function testReturnCreateRoleDraftResultInBeforeEvents()
1271
    {
1272
        $traceableEventDispatcher = $this->getEventDispatcher(
1273
            BeforeCreateRoleDraftEventInterface::class,
1274
            CreateRoleDraftEventInterface::class
1275
        );
1276
1277
        $parameters = [
1278
            $this->createMock(Role::class),
1279
        ];
1280
1281
        $roleDraft = $this->createMock(RoleDraft::class);
1282
        $eventRoleDraft = $this->createMock(RoleDraft::class);
1283
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1284
        $innerServiceMock->method('createRoleDraft')->willReturn($roleDraft);
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...
1285
1286
        $traceableEventDispatcher->addListener(BeforeCreateRoleDraftEventInterface::class, function (BeforeCreateRoleDraftEventInterface $event) use ($eventRoleDraft) {
1287
            $event->setRoleDraft($eventRoleDraft);
1288
        }, 10);
1289
1290
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1291
        $result = $service->createRoleDraft(...$parameters);
1292
1293
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1294
1295
        $this->assertSame($eventRoleDraft, $result);
1296
        $this->assertSame($calledListeners, [
1297
            [BeforeCreateRoleDraftEventInterface::class, 10],
1298
            [BeforeCreateRoleDraftEventInterface::class, 0],
1299
            [CreateRoleDraftEventInterface::class, 0],
1300
        ]);
1301
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1302
    }
1303
1304 View Code Duplication
    public function testCreateRoleDraftStopPropagationInBeforeEvents()
1305
    {
1306
        $traceableEventDispatcher = $this->getEventDispatcher(
1307
            BeforeCreateRoleDraftEventInterface::class,
1308
            CreateRoleDraftEventInterface::class
1309
        );
1310
1311
        $parameters = [
1312
            $this->createMock(Role::class),
1313
        ];
1314
1315
        $roleDraft = $this->createMock(RoleDraft::class);
1316
        $eventRoleDraft = $this->createMock(RoleDraft::class);
1317
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1318
        $innerServiceMock->method('createRoleDraft')->willReturn($roleDraft);
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...
1319
1320
        $traceableEventDispatcher->addListener(BeforeCreateRoleDraftEventInterface::class, function (BeforeCreateRoleDraftEventInterface $event) use ($eventRoleDraft) {
1321
            $event->setRoleDraft($eventRoleDraft);
1322
            $event->stopPropagation();
1323
        }, 10);
1324
1325
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1326
        $result = $service->createRoleDraft(...$parameters);
1327
1328
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1329
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1330
1331
        $this->assertSame($eventRoleDraft, $result);
1332
        $this->assertSame($calledListeners, [
1333
            [BeforeCreateRoleDraftEventInterface::class, 10],
1334
        ]);
1335
        $this->assertSame($notCalledListeners, [
1336
            [BeforeCreateRoleDraftEventInterface::class, 0],
1337
            [CreateRoleDraftEventInterface::class, 0],
1338
        ]);
1339
    }
1340
1341 View Code Duplication
    public function testUpdatePolicyEvents()
1342
    {
1343
        $traceableEventDispatcher = $this->getEventDispatcher(
1344
            BeforeUpdatePolicyEventInterface::class,
1345
            UpdatePolicyEventInterface::class
1346
        );
1347
1348
        $parameters = [
1349
            $this->createMock(Policy::class),
1350
            $this->createMock(PolicyUpdateStruct::class),
1351
        ];
1352
1353
        $updatedPolicy = $this->createMock(Policy::class);
1354
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1355
        $innerServiceMock->method('updatePolicy')->willReturn($updatedPolicy);
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...
1356
1357
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1358
        $result = $service->updatePolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicy() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
1359
1360
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1361
1362
        $this->assertSame($updatedPolicy, $result);
1363
        $this->assertSame($calledListeners, [
1364
            [BeforeUpdatePolicyEventInterface::class, 0],
1365
            [UpdatePolicyEventInterface::class, 0],
1366
        ]);
1367
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1368
    }
1369
1370 View Code Duplication
    public function testReturnUpdatePolicyResultInBeforeEvents()
1371
    {
1372
        $traceableEventDispatcher = $this->getEventDispatcher(
1373
            BeforeUpdatePolicyEventInterface::class,
1374
            UpdatePolicyEventInterface::class
1375
        );
1376
1377
        $parameters = [
1378
            $this->createMock(Policy::class),
1379
            $this->createMock(PolicyUpdateStruct::class),
1380
        ];
1381
1382
        $updatedPolicy = $this->createMock(Policy::class);
1383
        $eventUpdatedPolicy = $this->createMock(Policy::class);
1384
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1385
        $innerServiceMock->method('updatePolicy')->willReturn($updatedPolicy);
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...
1386
1387
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyEventInterface::class, function (BeforeUpdatePolicyEventInterface $event) use ($eventUpdatedPolicy) {
1388
            $event->setUpdatedPolicy($eventUpdatedPolicy);
1389
        }, 10);
1390
1391
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1392
        $result = $service->updatePolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicy() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
1393
1394
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1395
1396
        $this->assertSame($eventUpdatedPolicy, $result);
1397
        $this->assertSame($calledListeners, [
1398
            [BeforeUpdatePolicyEventInterface::class, 10],
1399
            [BeforeUpdatePolicyEventInterface::class, 0],
1400
            [UpdatePolicyEventInterface::class, 0],
1401
        ]);
1402
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1403
    }
1404
1405 View Code Duplication
    public function testUpdatePolicyStopPropagationInBeforeEvents()
1406
    {
1407
        $traceableEventDispatcher = $this->getEventDispatcher(
1408
            BeforeUpdatePolicyEventInterface::class,
1409
            UpdatePolicyEventInterface::class
1410
        );
1411
1412
        $parameters = [
1413
            $this->createMock(Policy::class),
1414
            $this->createMock(PolicyUpdateStruct::class),
1415
        ];
1416
1417
        $updatedPolicy = $this->createMock(Policy::class);
1418
        $eventUpdatedPolicy = $this->createMock(Policy::class);
1419
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1420
        $innerServiceMock->method('updatePolicy')->willReturn($updatedPolicy);
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...
1421
1422
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyEventInterface::class, function (BeforeUpdatePolicyEventInterface $event) use ($eventUpdatedPolicy) {
1423
            $event->setUpdatedPolicy($eventUpdatedPolicy);
1424
            $event->stopPropagation();
1425
        }, 10);
1426
1427
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1428
        $result = $service->updatePolicy(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicy() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
1429
1430
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1431
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1432
1433
        $this->assertSame($eventUpdatedPolicy, $result);
1434
        $this->assertSame($calledListeners, [
1435
            [BeforeUpdatePolicyEventInterface::class, 10],
1436
        ]);
1437
        $this->assertSame($notCalledListeners, [
1438
            [BeforeUpdatePolicyEventInterface::class, 0],
1439
            [UpdatePolicyEventInterface::class, 0],
1440
        ]);
1441
    }
1442
1443
    public function testUnassignRoleFromUserGroupEvents()
1444
    {
1445
        $traceableEventDispatcher = $this->getEventDispatcher(
1446
            BeforeUnassignRoleFromUserGroupEventInterface::class,
1447
            UnassignRoleFromUserGroupEventInterface::class
1448
        );
1449
1450
        $parameters = [
1451
            $this->createMock(Role::class),
1452
            $this->createMock(UserGroup::class),
1453
        ];
1454
1455
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1456
1457
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1458
        $service->unassignRoleFromUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unassignRoleFromUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
1459
1460
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1461
1462
        $this->assertSame($calledListeners, [
1463
            [BeforeUnassignRoleFromUserGroupEventInterface::class, 0],
1464
            [UnassignRoleFromUserGroupEventInterface::class, 0],
1465
        ]);
1466
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1467
    }
1468
1469 View Code Duplication
    public function testUnassignRoleFromUserGroupStopPropagationInBeforeEvents()
1470
    {
1471
        $traceableEventDispatcher = $this->getEventDispatcher(
1472
            BeforeUnassignRoleFromUserGroupEventInterface::class,
1473
            UnassignRoleFromUserGroupEventInterface::class
1474
        );
1475
1476
        $parameters = [
1477
            $this->createMock(Role::class),
1478
            $this->createMock(UserGroup::class),
1479
        ];
1480
1481
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
1482
1483
        $traceableEventDispatcher->addListener(BeforeUnassignRoleFromUserGroupEventInterface::class, function (BeforeUnassignRoleFromUserGroupEventInterface $event) {
1484
            $event->stopPropagation();
1485
        }, 10);
1486
1487
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
1488
        $service->unassignRoleFromUserGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to unassignRoleFromUserGroup() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
1489
1490
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1491
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1492
1493
        $this->assertSame($calledListeners, [
1494
            [BeforeUnassignRoleFromUserGroupEventInterface::class, 10],
1495
        ]);
1496
        $this->assertSame($notCalledListeners, [
1497
            [BeforeUnassignRoleFromUserGroupEventInterface::class, 0],
1498
            [UnassignRoleFromUserGroupEventInterface::class, 0],
1499
        ]);
1500
    }
1501
}
1502