Completed
Push — ezp-30928-as_a_developer_i_wan... ( 0570c5 )
by
unknown
13:48
created

RoleServiceTest::testPublishRoleDraftEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 24
rs 9.536
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;
10
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserEvent;
11
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserGroupEvent;
12
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyByRoleDraftEvent;
13
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserEvent;
14
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserGroupEvent;
15
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleDraftEvent;
16
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleEvent;
17
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleDraftEvent;
18
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleEvent;
19
use eZ\Publish\API\Repository\Events\Role\BeforePublishRoleDraftEvent;
20
use eZ\Publish\API\Repository\Events\Role\BeforeRemovePolicyByRoleDraftEvent;
21
use eZ\Publish\API\Repository\Events\Role\BeforeRemoveRoleAssignmentEvent;
22
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyByRoleDraftEvent;
23
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleDraftEvent;
24
use eZ\Publish\API\Repository\Events\Role\CreateRoleDraftEvent;
25
use eZ\Publish\API\Repository\Events\Role\CreateRoleEvent;
26
use eZ\Publish\API\Repository\Events\Role\DeleteRoleDraftEvent;
27
use eZ\Publish\API\Repository\Events\Role\DeleteRoleEvent;
28
use eZ\Publish\API\Repository\Events\Role\PublishRoleDraftEvent;
29
use eZ\Publish\API\Repository\Events\Role\RemovePolicyByRoleDraftEvent;
30
use eZ\Publish\API\Repository\Events\Role\RemoveRoleAssignmentEvent;
31
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyByRoleDraftEvent;
32
use eZ\Publish\API\Repository\Events\Role\UpdateRoleDraftEvent;
33
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
34
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
35
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
36
use eZ\Publish\API\Repository\Values\User\PolicyDraft;
37
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct;
38
use eZ\Publish\API\Repository\Values\User\Role;
39
use eZ\Publish\API\Repository\Values\User\RoleAssignment;
40
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct;
41
use eZ\Publish\API\Repository\Values\User\RoleDraft;
42
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
43
use eZ\Publish\API\Repository\Values\User\User;
44
use eZ\Publish\API\Repository\Values\User\UserGroup;
45
use eZ\Publish\Core\Event\RoleService;
46
47
class RoleServiceTest extends AbstractServiceTest
48
{
49
    public function testPublishRoleDraftEvents()
50
    {
51
        $traceableEventDispatcher = $this->getEventDispatcher(
52
            BeforePublishRoleDraftEvent::class,
53
            PublishRoleDraftEvent::class
54
        );
55
56
        $parameters = [
57
            $this->createMock(RoleDraft::class),
58
        ];
59
60
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
61
62
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
63
        $service->publishRoleDraft(...$parameters);
64
65
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
66
67
        $this->assertSame($calledListeners, [
68
            [BeforePublishRoleDraftEvent::class, 0],
69
            [PublishRoleDraftEvent::class, 0],
70
        ]);
71
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
72
    }
73
74
    public function testPublishRoleDraftStopPropagationInBeforeEvents()
75
    {
76
        $traceableEventDispatcher = $this->getEventDispatcher(
77
            BeforePublishRoleDraftEvent::class,
78
            PublishRoleDraftEvent::class
79
        );
80
81
        $parameters = [
82
            $this->createMock(RoleDraft::class),
83
        ];
84
85
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
86
87
        $traceableEventDispatcher->addListener(BeforePublishRoleDraftEvent::class, function (BeforePublishRoleDraftEvent $event) {
88
            $event->stopPropagation();
89
        }, 10);
90
91
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
92
        $service->publishRoleDraft(...$parameters);
93
94
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
95
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
96
97
        $this->assertSame($calledListeners, [
98
            [BeforePublishRoleDraftEvent::class, 10],
99
        ]);
100
        $this->assertSame($notCalledListeners, [
101
            [BeforePublishRoleDraftEvent::class, 0],
102
            [PublishRoleDraftEvent::class, 0],
103
        ]);
104
    }
105
106 View Code Duplication
    public function testAssignRoleToUserEvents()
107
    {
108
        $traceableEventDispatcher = $this->getEventDispatcher(
109
            BeforeAssignRoleToUserEvent::class,
110
            AssignRoleToUserEvent::class
111
        );
112
113
        $parameters = [
114
            $this->createMock(Role::class),
115
            $this->createMock(User::class),
116
            $this->createMock(RoleLimitation::class),
117
        ];
118
119
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
120
121
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
122
        $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...
123
124
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
125
126
        $this->assertSame($calledListeners, [
127
            [BeforeAssignRoleToUserEvent::class, 0],
128
            [AssignRoleToUserEvent::class, 0],
129
        ]);
130
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
131
    }
132
133 View Code Duplication
    public function testAssignRoleToUserStopPropagationInBeforeEvents()
134
    {
135
        $traceableEventDispatcher = $this->getEventDispatcher(
136
            BeforeAssignRoleToUserEvent::class,
137
            AssignRoleToUserEvent::class
138
        );
139
140
        $parameters = [
141
            $this->createMock(Role::class),
142
            $this->createMock(User::class),
143
            $this->createMock(RoleLimitation::class),
144
        ];
145
146
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
147
148
        $traceableEventDispatcher->addListener(BeforeAssignRoleToUserEvent::class, function (BeforeAssignRoleToUserEvent $event) {
149
            $event->stopPropagation();
150
        }, 10);
151
152
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
153
        $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...
154
155
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
156
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
157
158
        $this->assertSame($calledListeners, [
159
            [BeforeAssignRoleToUserEvent::class, 10],
160
        ]);
161
        $this->assertSame($notCalledListeners, [
162
            [AssignRoleToUserEvent::class, 0],
163
            [BeforeAssignRoleToUserEvent::class, 0],
164
        ]);
165
    }
166
167 View Code Duplication
    public function testUpdateRoleDraftEvents()
168
    {
169
        $traceableEventDispatcher = $this->getEventDispatcher(
170
            BeforeUpdateRoleDraftEvent::class,
171
            UpdateRoleDraftEvent::class
172
        );
173
174
        $parameters = [
175
            $this->createMock(RoleDraft::class),
176
            $this->createMock(RoleUpdateStruct::class),
177
        ];
178
179
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
180
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
181
        $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...
182
183
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
184
        $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...
185
186
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
187
188
        $this->assertSame($updatedRoleDraft, $result);
189
        $this->assertSame($calledListeners, [
190
            [BeforeUpdateRoleDraftEvent::class, 0],
191
            [UpdateRoleDraftEvent::class, 0],
192
        ]);
193
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
194
    }
195
196 View Code Duplication
    public function testReturnUpdateRoleDraftResultInBeforeEvents()
197
    {
198
        $traceableEventDispatcher = $this->getEventDispatcher(
199
            BeforeUpdateRoleDraftEvent::class,
200
            UpdateRoleDraftEvent::class
201
        );
202
203
        $parameters = [
204
            $this->createMock(RoleDraft::class),
205
            $this->createMock(RoleUpdateStruct::class),
206
        ];
207
208
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
209
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
210
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
211
        $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...
212
213
        $traceableEventDispatcher->addListener(BeforeUpdateRoleDraftEvent::class, function (BeforeUpdateRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
214
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
215
        }, 10);
216
217
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
218
        $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...
219
220
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
221
222
        $this->assertSame($eventUpdatedRoleDraft, $result);
223
        $this->assertSame($calledListeners, [
224
            [BeforeUpdateRoleDraftEvent::class, 10],
225
            [BeforeUpdateRoleDraftEvent::class, 0],
226
            [UpdateRoleDraftEvent::class, 0],
227
        ]);
228
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
229
    }
230
231 View Code Duplication
    public function testUpdateRoleDraftStopPropagationInBeforeEvents()
232
    {
233
        $traceableEventDispatcher = $this->getEventDispatcher(
234
            BeforeUpdateRoleDraftEvent::class,
235
            UpdateRoleDraftEvent::class
236
        );
237
238
        $parameters = [
239
            $this->createMock(RoleDraft::class),
240
            $this->createMock(RoleUpdateStruct::class),
241
        ];
242
243
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
244
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
245
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
246
        $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...
247
248
        $traceableEventDispatcher->addListener(BeforeUpdateRoleDraftEvent::class, function (BeforeUpdateRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
249
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
250
            $event->stopPropagation();
251
        }, 10);
252
253
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
254
        $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...
255
256
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
257
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
258
259
        $this->assertSame($eventUpdatedRoleDraft, $result);
260
        $this->assertSame($calledListeners, [
261
            [BeforeUpdateRoleDraftEvent::class, 10],
262
        ]);
263
        $this->assertSame($notCalledListeners, [
264
            [BeforeUpdateRoleDraftEvent::class, 0],
265
            [UpdateRoleDraftEvent::class, 0],
266
        ]);
267
    }
268
269 View Code Duplication
    public function testAssignRoleToUserGroupEvents()
270
    {
271
        $traceableEventDispatcher = $this->getEventDispatcher(
272
            BeforeAssignRoleToUserGroupEvent::class,
273
            AssignRoleToUserGroupEvent::class
274
        );
275
276
        $parameters = [
277
            $this->createMock(Role::class),
278
            $this->createMock(UserGroup::class),
279
            $this->createMock(RoleLimitation::class),
280
        ];
281
282
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
283
284
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
285
        $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...
286
287
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
288
289
        $this->assertSame($calledListeners, [
290
            [BeforeAssignRoleToUserGroupEvent::class, 0],
291
            [AssignRoleToUserGroupEvent::class, 0],
292
        ]);
293
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
294
    }
295
296 View Code Duplication
    public function testAssignRoleToUserGroupStopPropagationInBeforeEvents()
297
    {
298
        $traceableEventDispatcher = $this->getEventDispatcher(
299
            BeforeAssignRoleToUserGroupEvent::class,
300
            AssignRoleToUserGroupEvent::class
301
        );
302
303
        $parameters = [
304
            $this->createMock(Role::class),
305
            $this->createMock(UserGroup::class),
306
            $this->createMock(RoleLimitation::class),
307
        ];
308
309
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
310
311
        $traceableEventDispatcher->addListener(BeforeAssignRoleToUserGroupEvent::class, function (BeforeAssignRoleToUserGroupEvent $event) {
312
            $event->stopPropagation();
313
        }, 10);
314
315
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
316
        $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...
317
318
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
319
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
320
321
        $this->assertSame($calledListeners, [
322
            [BeforeAssignRoleToUserGroupEvent::class, 10],
323
        ]);
324
        $this->assertSame($notCalledListeners, [
325
            [AssignRoleToUserGroupEvent::class, 0],
326
            [BeforeAssignRoleToUserGroupEvent::class, 0],
327
        ]);
328
    }
329
330 View Code Duplication
    public function testUpdatePolicyByRoleDraftEvents()
331
    {
332
        $traceableEventDispatcher = $this->getEventDispatcher(
333
            BeforeUpdatePolicyByRoleDraftEvent::class,
334
            UpdatePolicyByRoleDraftEvent::class
335
        );
336
337
        $parameters = [
338
            $this->createMock(RoleDraft::class),
339
            $this->createMock(PolicyDraft::class),
340
            $this->createMock(PolicyUpdateStruct::class),
341
        ];
342
343
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
344
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
345
        $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...
346
347
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
348
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
349
350
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
351
352
        $this->assertSame($updatedPolicyDraft, $result);
353
        $this->assertSame($calledListeners, [
354
            [BeforeUpdatePolicyByRoleDraftEvent::class, 0],
355
            [UpdatePolicyByRoleDraftEvent::class, 0],
356
        ]);
357
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
358
    }
359
360
    public function testReturnUpdatePolicyByRoleDraftResultInBeforeEvents()
361
    {
362
        $traceableEventDispatcher = $this->getEventDispatcher(
363
            BeforeUpdatePolicyByRoleDraftEvent::class,
364
            UpdatePolicyByRoleDraftEvent::class
365
        );
366
367
        $parameters = [
368
            $this->createMock(RoleDraft::class),
369
            $this->createMock(PolicyDraft::class),
370
            $this->createMock(PolicyUpdateStruct::class),
371
        ];
372
373
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
374
        $eventUpdatedPolicyDraft = $this->createMock(PolicyDraft::class);
375
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
376
        $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...
377
378
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyByRoleDraftEvent::class, function (BeforeUpdatePolicyByRoleDraftEvent $event) use ($eventUpdatedPolicyDraft) {
379
            $event->setUpdatedPolicyDraft($eventUpdatedPolicyDraft);
380
        }, 10);
381
382
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
383
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
384
385
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
386
387
        $this->assertSame($eventUpdatedPolicyDraft, $result);
388
        $this->assertSame($calledListeners, [
389
            [BeforeUpdatePolicyByRoleDraftEvent::class, 10],
390
            [BeforeUpdatePolicyByRoleDraftEvent::class, 0],
391
            [UpdatePolicyByRoleDraftEvent::class, 0],
392
        ]);
393
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
394
    }
395
396
    public function testUpdatePolicyByRoleDraftStopPropagationInBeforeEvents()
397
    {
398
        $traceableEventDispatcher = $this->getEventDispatcher(
399
            BeforeUpdatePolicyByRoleDraftEvent::class,
400
            UpdatePolicyByRoleDraftEvent::class
401
        );
402
403
        $parameters = [
404
            $this->createMock(RoleDraft::class),
405
            $this->createMock(PolicyDraft::class),
406
            $this->createMock(PolicyUpdateStruct::class),
407
        ];
408
409
        $updatedPolicyDraft = $this->createMock(PolicyDraft::class);
410
        $eventUpdatedPolicyDraft = $this->createMock(PolicyDraft::class);
411
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
412
        $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...
413
414
        $traceableEventDispatcher->addListener(BeforeUpdatePolicyByRoleDraftEvent::class, function (BeforeUpdatePolicyByRoleDraftEvent $event) use ($eventUpdatedPolicyDraft) {
415
            $event->setUpdatedPolicyDraft($eventUpdatedPolicyDraft);
416
            $event->stopPropagation();
417
        }, 10);
418
419
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
420
        $result = $service->updatePolicyByRoleDraft(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updatePolicyByRoleDraft() misses some required arguments starting with $policy.
Loading history...
421
422
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
423
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
424
425
        $this->assertSame($eventUpdatedPolicyDraft, $result);
426
        $this->assertSame($calledListeners, [
427
            [BeforeUpdatePolicyByRoleDraftEvent::class, 10],
428
        ]);
429
        $this->assertSame($notCalledListeners, [
430
            [BeforeUpdatePolicyByRoleDraftEvent::class, 0],
431
            [UpdatePolicyByRoleDraftEvent::class, 0],
432
        ]);
433
    }
434
435 View Code Duplication
    public function testCreateRoleEvents()
436
    {
437
        $traceableEventDispatcher = $this->getEventDispatcher(
438
            BeforeCreateRoleEvent::class,
439
            CreateRoleEvent::class
440
        );
441
442
        $parameters = [
443
            $this->createMock(RoleCreateStruct::class),
444
        ];
445
446
        $roleDraft = $this->createMock(RoleDraft::class);
447
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
448
        $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...
449
450
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
451
        $result = $service->createRole(...$parameters);
452
453
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
454
455
        $this->assertSame($roleDraft, $result);
456
        $this->assertSame($calledListeners, [
457
            [BeforeCreateRoleEvent::class, 0],
458
            [CreateRoleEvent::class, 0],
459
        ]);
460
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
461
    }
462
463 View Code Duplication
    public function testReturnCreateRoleResultInBeforeEvents()
464
    {
465
        $traceableEventDispatcher = $this->getEventDispatcher(
466
            BeforeCreateRoleEvent::class,
467
            CreateRoleEvent::class
468
        );
469
470
        $parameters = [
471
            $this->createMock(RoleCreateStruct::class),
472
        ];
473
474
        $roleDraft = $this->createMock(RoleDraft::class);
475
        $eventRoleDraft = $this->createMock(RoleDraft::class);
476
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
477
        $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...
478
479
        $traceableEventDispatcher->addListener(BeforeCreateRoleEvent::class, function (BeforeCreateRoleEvent $event) use ($eventRoleDraft) {
480
            $event->setRoleDraft($eventRoleDraft);
481
        }, 10);
482
483
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
484
        $result = $service->createRole(...$parameters);
485
486
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
487
488
        $this->assertSame($eventRoleDraft, $result);
489
        $this->assertSame($calledListeners, [
490
            [BeforeCreateRoleEvent::class, 10],
491
            [BeforeCreateRoleEvent::class, 0],
492
            [CreateRoleEvent::class, 0],
493
        ]);
494
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
495
    }
496
497 View Code Duplication
    public function testCreateRoleStopPropagationInBeforeEvents()
498
    {
499
        $traceableEventDispatcher = $this->getEventDispatcher(
500
            BeforeCreateRoleEvent::class,
501
            CreateRoleEvent::class
502
        );
503
504
        $parameters = [
505
            $this->createMock(RoleCreateStruct::class),
506
        ];
507
508
        $roleDraft = $this->createMock(RoleDraft::class);
509
        $eventRoleDraft = $this->createMock(RoleDraft::class);
510
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
511
        $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...
512
513
        $traceableEventDispatcher->addListener(BeforeCreateRoleEvent::class, function (BeforeCreateRoleEvent $event) use ($eventRoleDraft) {
514
            $event->setRoleDraft($eventRoleDraft);
515
            $event->stopPropagation();
516
        }, 10);
517
518
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
519
        $result = $service->createRole(...$parameters);
520
521
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
522
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
523
524
        $this->assertSame($eventRoleDraft, $result);
525
        $this->assertSame($calledListeners, [
526
            [BeforeCreateRoleEvent::class, 10],
527
        ]);
528
        $this->assertSame($notCalledListeners, [
529
            [BeforeCreateRoleEvent::class, 0],
530
            [CreateRoleEvent::class, 0],
531
        ]);
532
    }
533
534 View Code Duplication
    public function testRemovePolicyByRoleDraftEvents()
535
    {
536
        $traceableEventDispatcher = $this->getEventDispatcher(
537
            BeforeRemovePolicyByRoleDraftEvent::class,
538
            RemovePolicyByRoleDraftEvent::class
539
        );
540
541
        $parameters = [
542
            $this->createMock(RoleDraft::class),
543
            $this->createMock(PolicyDraft::class),
544
        ];
545
546
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
547
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
548
        $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...
549
550
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
551
        $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...
552
553
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
554
555
        $this->assertSame($updatedRoleDraft, $result);
556
        $this->assertSame($calledListeners, [
557
            [BeforeRemovePolicyByRoleDraftEvent::class, 0],
558
            [RemovePolicyByRoleDraftEvent::class, 0],
559
        ]);
560
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
561
    }
562
563 View Code Duplication
    public function testReturnRemovePolicyByRoleDraftResultInBeforeEvents()
564
    {
565
        $traceableEventDispatcher = $this->getEventDispatcher(
566
            BeforeRemovePolicyByRoleDraftEvent::class,
567
            RemovePolicyByRoleDraftEvent::class
568
        );
569
570
        $parameters = [
571
            $this->createMock(RoleDraft::class),
572
            $this->createMock(PolicyDraft::class),
573
        ];
574
575
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
576
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
577
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
578
        $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...
579
580
        $traceableEventDispatcher->addListener(BeforeRemovePolicyByRoleDraftEvent::class, function (BeforeRemovePolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
581
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
582
        }, 10);
583
584
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
585
        $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...
586
587
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
588
589
        $this->assertSame($eventUpdatedRoleDraft, $result);
590
        $this->assertSame($calledListeners, [
591
            [BeforeRemovePolicyByRoleDraftEvent::class, 10],
592
            [BeforeRemovePolicyByRoleDraftEvent::class, 0],
593
            [RemovePolicyByRoleDraftEvent::class, 0],
594
        ]);
595
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
596
    }
597
598 View Code Duplication
    public function testRemovePolicyByRoleDraftStopPropagationInBeforeEvents()
599
    {
600
        $traceableEventDispatcher = $this->getEventDispatcher(
601
            BeforeRemovePolicyByRoleDraftEvent::class,
602
            RemovePolicyByRoleDraftEvent::class
603
        );
604
605
        $parameters = [
606
            $this->createMock(RoleDraft::class),
607
            $this->createMock(PolicyDraft::class),
608
        ];
609
610
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
611
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
612
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
613
        $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...
614
615
        $traceableEventDispatcher->addListener(BeforeRemovePolicyByRoleDraftEvent::class, function (BeforeRemovePolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
616
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
617
            $event->stopPropagation();
618
        }, 10);
619
620
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
621
        $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...
622
623
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
624
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
625
626
        $this->assertSame($eventUpdatedRoleDraft, $result);
627
        $this->assertSame($calledListeners, [
628
            [BeforeRemovePolicyByRoleDraftEvent::class, 10],
629
        ]);
630
        $this->assertSame($notCalledListeners, [
631
            [BeforeRemovePolicyByRoleDraftEvent::class, 0],
632
            [RemovePolicyByRoleDraftEvent::class, 0],
633
        ]);
634
    }
635
636 View Code Duplication
    public function testAddPolicyByRoleDraftEvents()
637
    {
638
        $traceableEventDispatcher = $this->getEventDispatcher(
639
            BeforeAddPolicyByRoleDraftEvent::class,
640
            AddPolicyByRoleDraftEvent::class
641
        );
642
643
        $parameters = [
644
            $this->createMock(RoleDraft::class),
645
            $this->createMock(PolicyCreateStruct::class),
646
        ];
647
648
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
649
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
650
        $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...
651
652
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
653
        $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...
654
655
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
656
657
        $this->assertSame($updatedRoleDraft, $result);
658
        $this->assertSame($calledListeners, [
659
            [BeforeAddPolicyByRoleDraftEvent::class, 0],
660
            [AddPolicyByRoleDraftEvent::class, 0],
661
        ]);
662
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
663
    }
664
665 View Code Duplication
    public function testReturnAddPolicyByRoleDraftResultInBeforeEvents()
666
    {
667
        $traceableEventDispatcher = $this->getEventDispatcher(
668
            BeforeAddPolicyByRoleDraftEvent::class,
669
            AddPolicyByRoleDraftEvent::class
670
        );
671
672
        $parameters = [
673
            $this->createMock(RoleDraft::class),
674
            $this->createMock(PolicyCreateStruct::class),
675
        ];
676
677
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
678
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
679
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
680
        $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...
681
682
        $traceableEventDispatcher->addListener(BeforeAddPolicyByRoleDraftEvent::class, function (BeforeAddPolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
683
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
684
        }, 10);
685
686
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
687
        $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...
688
689
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
690
691
        $this->assertSame($eventUpdatedRoleDraft, $result);
692
        $this->assertSame($calledListeners, [
693
            [BeforeAddPolicyByRoleDraftEvent::class, 10],
694
            [BeforeAddPolicyByRoleDraftEvent::class, 0],
695
            [AddPolicyByRoleDraftEvent::class, 0],
696
        ]);
697
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
698
    }
699
700 View Code Duplication
    public function testAddPolicyByRoleDraftStopPropagationInBeforeEvents()
701
    {
702
        $traceableEventDispatcher = $this->getEventDispatcher(
703
            BeforeAddPolicyByRoleDraftEvent::class,
704
            AddPolicyByRoleDraftEvent::class
705
        );
706
707
        $parameters = [
708
            $this->createMock(RoleDraft::class),
709
            $this->createMock(PolicyCreateStruct::class),
710
        ];
711
712
        $updatedRoleDraft = $this->createMock(RoleDraft::class);
713
        $eventUpdatedRoleDraft = $this->createMock(RoleDraft::class);
714
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
715
        $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...
716
717
        $traceableEventDispatcher->addListener(BeforeAddPolicyByRoleDraftEvent::class, function (BeforeAddPolicyByRoleDraftEvent $event) use ($eventUpdatedRoleDraft) {
718
            $event->setUpdatedRoleDraft($eventUpdatedRoleDraft);
719
            $event->stopPropagation();
720
        }, 10);
721
722
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
723
        $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...
724
725
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
726
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
727
728
        $this->assertSame($eventUpdatedRoleDraft, $result);
729
        $this->assertSame($calledListeners, [
730
            [BeforeAddPolicyByRoleDraftEvent::class, 10],
731
        ]);
732
        $this->assertSame($notCalledListeners, [
733
            [AddPolicyByRoleDraftEvent::class, 0],
734
            [BeforeAddPolicyByRoleDraftEvent::class, 0],
735
        ]);
736
    }
737
738
    public function testDeleteRoleEvents()
739
    {
740
        $traceableEventDispatcher = $this->getEventDispatcher(
741
            BeforeDeleteRoleEvent::class,
742
            DeleteRoleEvent::class
743
        );
744
745
        $parameters = [
746
            $this->createMock(Role::class),
747
        ];
748
749
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
750
751
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
752
        $service->deleteRole(...$parameters);
753
754
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
755
756
        $this->assertSame($calledListeners, [
757
            [BeforeDeleteRoleEvent::class, 0],
758
            [DeleteRoleEvent::class, 0],
759
        ]);
760
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
761
    }
762
763
    public function testDeleteRoleStopPropagationInBeforeEvents()
764
    {
765
        $traceableEventDispatcher = $this->getEventDispatcher(
766
            BeforeDeleteRoleEvent::class,
767
            DeleteRoleEvent::class
768
        );
769
770
        $parameters = [
771
            $this->createMock(Role::class),
772
        ];
773
774
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
775
776
        $traceableEventDispatcher->addListener(BeforeDeleteRoleEvent::class, function (BeforeDeleteRoleEvent $event) {
777
            $event->stopPropagation();
778
        }, 10);
779
780
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
781
        $service->deleteRole(...$parameters);
782
783
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
784
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
785
786
        $this->assertSame($calledListeners, [
787
            [BeforeDeleteRoleEvent::class, 10],
788
        ]);
789
        $this->assertSame($notCalledListeners, [
790
            [BeforeDeleteRoleEvent::class, 0],
791
            [DeleteRoleEvent::class, 0],
792
        ]);
793
    }
794
795
    public function testDeleteRoleDraftEvents()
796
    {
797
        $traceableEventDispatcher = $this->getEventDispatcher(
798
            BeforeDeleteRoleDraftEvent::class,
799
            DeleteRoleDraftEvent::class
800
        );
801
802
        $parameters = [
803
            $this->createMock(RoleDraft::class),
804
        ];
805
806
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
807
808
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
809
        $service->deleteRoleDraft(...$parameters);
810
811
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
812
813
        $this->assertSame($calledListeners, [
814
            [BeforeDeleteRoleDraftEvent::class, 0],
815
            [DeleteRoleDraftEvent::class, 0],
816
        ]);
817
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
818
    }
819
820
    public function testDeleteRoleDraftStopPropagationInBeforeEvents()
821
    {
822
        $traceableEventDispatcher = $this->getEventDispatcher(
823
            BeforeDeleteRoleDraftEvent::class,
824
            DeleteRoleDraftEvent::class
825
        );
826
827
        $parameters = [
828
            $this->createMock(RoleDraft::class),
829
        ];
830
831
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
832
833
        $traceableEventDispatcher->addListener(BeforeDeleteRoleDraftEvent::class, function (BeforeDeleteRoleDraftEvent $event) {
834
            $event->stopPropagation();
835
        }, 10);
836
837
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
838
        $service->deleteRoleDraft(...$parameters);
839
840
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
841
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
842
843
        $this->assertSame($calledListeners, [
844
            [BeforeDeleteRoleDraftEvent::class, 10],
845
        ]);
846
        $this->assertSame($notCalledListeners, [
847
            [BeforeDeleteRoleDraftEvent::class, 0],
848
            [DeleteRoleDraftEvent::class, 0],
849
        ]);
850
    }
851
852
    public function testRemoveRoleAssignmentEvents()
853
    {
854
        $traceableEventDispatcher = $this->getEventDispatcher(
855
            BeforeRemoveRoleAssignmentEvent::class,
856
            RemoveRoleAssignmentEvent::class
857
        );
858
859
        $parameters = [
860
            $this->createMock(RoleAssignment::class),
861
        ];
862
863
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
864
865
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
866
        $service->removeRoleAssignment(...$parameters);
867
868
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
869
870
        $this->assertSame($calledListeners, [
871
            [BeforeRemoveRoleAssignmentEvent::class, 0],
872
            [RemoveRoleAssignmentEvent::class, 0],
873
        ]);
874
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
875
    }
876
877
    public function testRemoveRoleAssignmentStopPropagationInBeforeEvents()
878
    {
879
        $traceableEventDispatcher = $this->getEventDispatcher(
880
            BeforeRemoveRoleAssignmentEvent::class,
881
            RemoveRoleAssignmentEvent::class
882
        );
883
884
        $parameters = [
885
            $this->createMock(RoleAssignment::class),
886
        ];
887
888
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
889
890
        $traceableEventDispatcher->addListener(BeforeRemoveRoleAssignmentEvent::class, function (BeforeRemoveRoleAssignmentEvent $event) {
891
            $event->stopPropagation();
892
        }, 10);
893
894
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
895
        $service->removeRoleAssignment(...$parameters);
896
897
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
898
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
899
900
        $this->assertSame($calledListeners, [
901
            [BeforeRemoveRoleAssignmentEvent::class, 10],
902
        ]);
903
        $this->assertSame($notCalledListeners, [
904
            [BeforeRemoveRoleAssignmentEvent::class, 0],
905
            [RemoveRoleAssignmentEvent::class, 0],
906
        ]);
907
    }
908
909 View Code Duplication
    public function testCreateRoleDraftEvents()
910
    {
911
        $traceableEventDispatcher = $this->getEventDispatcher(
912
            BeforeCreateRoleDraftEvent::class,
913
            CreateRoleDraftEvent::class
914
        );
915
916
        $parameters = [
917
            $this->createMock(Role::class),
918
        ];
919
920
        $roleDraft = $this->createMock(RoleDraft::class);
921
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
922
        $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...
923
924
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
925
        $result = $service->createRoleDraft(...$parameters);
926
927
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
928
929
        $this->assertSame($roleDraft, $result);
930
        $this->assertSame($calledListeners, [
931
            [BeforeCreateRoleDraftEvent::class, 0],
932
            [CreateRoleDraftEvent::class, 0],
933
        ]);
934
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
935
    }
936
937 View Code Duplication
    public function testReturnCreateRoleDraftResultInBeforeEvents()
938
    {
939
        $traceableEventDispatcher = $this->getEventDispatcher(
940
            BeforeCreateRoleDraftEvent::class,
941
            CreateRoleDraftEvent::class
942
        );
943
944
        $parameters = [
945
            $this->createMock(Role::class),
946
        ];
947
948
        $roleDraft = $this->createMock(RoleDraft::class);
949
        $eventRoleDraft = $this->createMock(RoleDraft::class);
950
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
951
        $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...
952
953
        $traceableEventDispatcher->addListener(BeforeCreateRoleDraftEvent::class, function (BeforeCreateRoleDraftEvent $event) use ($eventRoleDraft) {
954
            $event->setRoleDraft($eventRoleDraft);
955
        }, 10);
956
957
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
958
        $result = $service->createRoleDraft(...$parameters);
959
960
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
961
962
        $this->assertSame($eventRoleDraft, $result);
963
        $this->assertSame($calledListeners, [
964
            [BeforeCreateRoleDraftEvent::class, 10],
965
            [BeforeCreateRoleDraftEvent::class, 0],
966
            [CreateRoleDraftEvent::class, 0],
967
        ]);
968
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
969
    }
970
971 View Code Duplication
    public function testCreateRoleDraftStopPropagationInBeforeEvents()
972
    {
973
        $traceableEventDispatcher = $this->getEventDispatcher(
974
            BeforeCreateRoleDraftEvent::class,
975
            CreateRoleDraftEvent::class
976
        );
977
978
        $parameters = [
979
            $this->createMock(Role::class),
980
        ];
981
982
        $roleDraft = $this->createMock(RoleDraft::class);
983
        $eventRoleDraft = $this->createMock(RoleDraft::class);
984
        $innerServiceMock = $this->createMock(RoleServiceInterface::class);
985
        $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...
986
987
        $traceableEventDispatcher->addListener(BeforeCreateRoleDraftEvent::class, function (BeforeCreateRoleDraftEvent $event) use ($eventRoleDraft) {
988
            $event->setRoleDraft($eventRoleDraft);
989
            $event->stopPropagation();
990
        }, 10);
991
992
        $service = new RoleService($innerServiceMock, $traceableEventDispatcher);
993
        $result = $service->createRoleDraft(...$parameters);
994
995
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
996
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
997
998
        $this->assertSame($eventRoleDraft, $result);
999
        $this->assertSame($calledListeners, [
1000
            [BeforeCreateRoleDraftEvent::class, 10],
1001
        ]);
1002
        $this->assertSame($notCalledListeners, [
1003
            [BeforeCreateRoleDraftEvent::class, 0],
1004
            [CreateRoleDraftEvent::class, 0],
1005
        ]);
1006
    }
1007
}
1008