Completed
Push — ezp-30616 ( 8e069f...7bf8e8 )
by
unknown
23:24 queued 01:36
created

ObjectStateServiceTest   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 641
Duplicated Lines 55.54 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
dl 356
loc 641
rs 9.959
c 0
b 0
f 0
wmc 20
lcom 1
cbo 11

20 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetContentStateEvents() 26 26 1
A testSetContentStateStopPropagationInBeforeEvents() 33 33 1
A testCreateObjectStateGroupEvents() 0 27 1
A testReturnCreateObjectStateGroupResultInBeforeEvents() 0 33 1
A testCreateObjectStateGroupStopPropagationInBeforeEvents() 0 36 1
A testUpdateObjectStateEvents() 28 28 1
A testReturnUpdateObjectStateResultInBeforeEvents() 34 34 1
A testUpdateObjectStateStopPropagationInBeforeEvents() 37 37 1
A testCreateObjectStateEvents() 28 28 1
A testReturnCreateObjectStateResultInBeforeEvents() 34 34 1
A testCreateObjectStateStopPropagationInBeforeEvents() 37 37 1
A testUpdateObjectStateGroupEvents() 28 28 1
A testReturnUpdateObjectStateGroupResultInBeforeEvents() 34 34 1
A testUpdateObjectStateGroupStopPropagationInBeforeEvents() 37 37 1
A testSetPriorityOfObjectStateEvents() 0 25 1
A testSetPriorityOfObjectStateStopPropagationInBeforeEvents() 0 32 1
A testDeleteObjectStateGroupEvents() 0 24 1
A testDeleteObjectStateGroupStopPropagationInBeforeEvents() 0 31 1
A testDeleteObjectStateEvents() 0 24 1
A testDeleteObjectStateStopPropagationInBeforeEvents() 0 31 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ObjectStateService as ObjectStateServiceInterface;
10
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
11
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
12
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
13
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
14
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct;
15
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct;
16
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct;
17
use eZ\Publish\Core\Event\ObjectStateService;
18
use eZ\Publish\Core\Event\ObjectState\BeforeCreateObjectStateEvent;
19
use eZ\Publish\Core\Event\ObjectState\BeforeCreateObjectStateGroupEvent;
20
use eZ\Publish\Core\Event\ObjectState\BeforeDeleteObjectStateEvent;
21
use eZ\Publish\Core\Event\ObjectState\BeforeDeleteObjectStateGroupEvent;
22
use eZ\Publish\Core\Event\ObjectState\BeforeSetContentStateEvent;
23
use eZ\Publish\Core\Event\ObjectState\BeforeSetPriorityOfObjectStateEvent;
24
use eZ\Publish\Core\Event\ObjectState\BeforeUpdateObjectStateEvent;
25
use eZ\Publish\Core\Event\ObjectState\BeforeUpdateObjectStateGroupEvent;
26
use eZ\Publish\Core\Event\ObjectState\ObjectStateEvents;
27
28
class ObjectStateServiceTest extends AbstractServiceTest
29
{
30 View Code Duplication
    public function testSetContentStateEvents()
31
    {
32
        $traceableEventDispatcher = $this->getEventDispatcher(
33
            ObjectStateEvents::BEFORE_SET_CONTENT_STATE,
34
            ObjectStateEvents::SET_CONTENT_STATE
35
        );
36
37
        $parameters = [
38
            $this->createMock(ContentInfo::class),
39
            $this->createMock(ObjectStateGroup::class),
40
            $this->createMock(ObjectState::class),
41
        ];
42
43
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
44
45
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
46
        $service->setContentState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setContentState() misses some required arguments starting with $objectStateGroup.
Loading history...
47
48
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
49
50
        $this->assertSame($calledListeners, [
51
            [ObjectStateEvents::BEFORE_SET_CONTENT_STATE, 0],
52
            [ObjectStateEvents::SET_CONTENT_STATE, 0],
53
        ]);
54
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
55
    }
56
57 View Code Duplication
    public function testSetContentStateStopPropagationInBeforeEvents()
58
    {
59
        $traceableEventDispatcher = $this->getEventDispatcher(
60
            ObjectStateEvents::BEFORE_SET_CONTENT_STATE,
61
            ObjectStateEvents::SET_CONTENT_STATE
62
        );
63
64
        $parameters = [
65
            $this->createMock(ContentInfo::class),
66
            $this->createMock(ObjectStateGroup::class),
67
            $this->createMock(ObjectState::class),
68
        ];
69
70
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
71
72
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_SET_CONTENT_STATE, function (BeforeSetContentStateEvent $event) {
73
            $event->stopPropagation();
74
        }, 10);
75
76
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
77
        $service->setContentState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setContentState() misses some required arguments starting with $objectStateGroup.
Loading history...
78
79
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
80
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
81
82
        $this->assertSame($calledListeners, [
83
            [ObjectStateEvents::BEFORE_SET_CONTENT_STATE, 10],
84
        ]);
85
        $this->assertSame($notCalledListeners, [
86
            [ObjectStateEvents::SET_CONTENT_STATE, 0],
87
            [ObjectStateEvents::BEFORE_SET_CONTENT_STATE, 0],
88
        ]);
89
    }
90
91
    public function testCreateObjectStateGroupEvents()
92
    {
93
        $traceableEventDispatcher = $this->getEventDispatcher(
94
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP,
95
            ObjectStateEvents::CREATE_OBJECT_STATE_GROUP
96
        );
97
98
        $parameters = [
99
            $this->createMock(ObjectStateGroupCreateStruct::class),
100
        ];
101
102
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
103
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
104
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
105
106
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
107
        $result = $service->createObjectStateGroup(...$parameters);
108
109
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
110
111
        $this->assertSame($objectStateGroup, $result);
112
        $this->assertSame($calledListeners, [
113
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, 0],
114
            [ObjectStateEvents::CREATE_OBJECT_STATE_GROUP, 0],
115
        ]);
116
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
117
    }
118
119
    public function testReturnCreateObjectStateGroupResultInBeforeEvents()
120
    {
121
        $traceableEventDispatcher = $this->getEventDispatcher(
122
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP,
123
            ObjectStateEvents::CREATE_OBJECT_STATE_GROUP
124
        );
125
126
        $parameters = [
127
            $this->createMock(ObjectStateGroupCreateStruct::class),
128
        ];
129
130
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
131
        $eventObjectStateGroup = $this->createMock(ObjectStateGroup::class);
132
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
133
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
134
135
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, function (BeforeCreateObjectStateGroupEvent $event) use ($eventObjectStateGroup) {
136
            $event->setObjectStateGroup($eventObjectStateGroup);
137
        }, 10);
138
139
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
140
        $result = $service->createObjectStateGroup(...$parameters);
141
142
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
143
144
        $this->assertSame($eventObjectStateGroup, $result);
145
        $this->assertSame($calledListeners, [
146
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, 10],
147
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, 0],
148
            [ObjectStateEvents::CREATE_OBJECT_STATE_GROUP, 0],
149
        ]);
150
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
151
    }
152
153
    public function testCreateObjectStateGroupStopPropagationInBeforeEvents()
154
    {
155
        $traceableEventDispatcher = $this->getEventDispatcher(
156
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP,
157
            ObjectStateEvents::CREATE_OBJECT_STATE_GROUP
158
        );
159
160
        $parameters = [
161
            $this->createMock(ObjectStateGroupCreateStruct::class),
162
        ];
163
164
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
165
        $eventObjectStateGroup = $this->createMock(ObjectStateGroup::class);
166
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
167
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
168
169
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, function (BeforeCreateObjectStateGroupEvent $event) use ($eventObjectStateGroup) {
170
            $event->setObjectStateGroup($eventObjectStateGroup);
171
            $event->stopPropagation();
172
        }, 10);
173
174
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
175
        $result = $service->createObjectStateGroup(...$parameters);
176
177
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
178
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
179
180
        $this->assertSame($eventObjectStateGroup, $result);
181
        $this->assertSame($calledListeners, [
182
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, 10],
183
        ]);
184
        $this->assertSame($notCalledListeners, [
185
            [ObjectStateEvents::CREATE_OBJECT_STATE_GROUP, 0],
186
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, 0],
187
        ]);
188
    }
189
190 View Code Duplication
    public function testUpdateObjectStateEvents()
191
    {
192
        $traceableEventDispatcher = $this->getEventDispatcher(
193
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE,
194
            ObjectStateEvents::UPDATE_OBJECT_STATE
195
        );
196
197
        $parameters = [
198
            $this->createMock(ObjectState::class),
199
            $this->createMock(ObjectStateUpdateStruct::class),
200
        ];
201
202
        $updatedObjectState = $this->createMock(ObjectState::class);
203
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
204
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
205
206
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
207
        $result = $service->updateObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectState() misses a required argument $objectStateUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
208
209
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
210
211
        $this->assertSame($updatedObjectState, $result);
212
        $this->assertSame($calledListeners, [
213
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 0],
214
            [ObjectStateEvents::UPDATE_OBJECT_STATE, 0],
215
        ]);
216
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
217
    }
218
219 View Code Duplication
    public function testReturnUpdateObjectStateResultInBeforeEvents()
220
    {
221
        $traceableEventDispatcher = $this->getEventDispatcher(
222
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE,
223
            ObjectStateEvents::UPDATE_OBJECT_STATE
224
        );
225
226
        $parameters = [
227
            $this->createMock(ObjectState::class),
228
            $this->createMock(ObjectStateUpdateStruct::class),
229
        ];
230
231
        $updatedObjectState = $this->createMock(ObjectState::class);
232
        $eventUpdatedObjectState = $this->createMock(ObjectState::class);
233
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
234
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
235
236
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, function (BeforeUpdateObjectStateEvent $event) use ($eventUpdatedObjectState) {
237
            $event->setUpdatedObjectState($eventUpdatedObjectState);
238
        }, 10);
239
240
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
241
        $result = $service->updateObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectState() misses a required argument $objectStateUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
242
243
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
244
245
        $this->assertSame($eventUpdatedObjectState, $result);
246
        $this->assertSame($calledListeners, [
247
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 10],
248
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 0],
249
            [ObjectStateEvents::UPDATE_OBJECT_STATE, 0],
250
        ]);
251
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
252
    }
253
254 View Code Duplication
    public function testUpdateObjectStateStopPropagationInBeforeEvents()
255
    {
256
        $traceableEventDispatcher = $this->getEventDispatcher(
257
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE,
258
            ObjectStateEvents::UPDATE_OBJECT_STATE
259
        );
260
261
        $parameters = [
262
            $this->createMock(ObjectState::class),
263
            $this->createMock(ObjectStateUpdateStruct::class),
264
        ];
265
266
        $updatedObjectState = $this->createMock(ObjectState::class);
267
        $eventUpdatedObjectState = $this->createMock(ObjectState::class);
268
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
269
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
270
271
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, function (BeforeUpdateObjectStateEvent $event) use ($eventUpdatedObjectState) {
272
            $event->setUpdatedObjectState($eventUpdatedObjectState);
273
            $event->stopPropagation();
274
        }, 10);
275
276
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
277
        $result = $service->updateObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectState() misses a required argument $objectStateUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
278
279
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
280
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
281
282
        $this->assertSame($eventUpdatedObjectState, $result);
283
        $this->assertSame($calledListeners, [
284
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 10],
285
        ]);
286
        $this->assertSame($notCalledListeners, [
287
            [ObjectStateEvents::UPDATE_OBJECT_STATE, 0],
288
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, 0],
289
        ]);
290
    }
291
292 View Code Duplication
    public function testCreateObjectStateEvents()
293
    {
294
        $traceableEventDispatcher = $this->getEventDispatcher(
295
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE,
296
            ObjectStateEvents::CREATE_OBJECT_STATE
297
        );
298
299
        $parameters = [
300
            $this->createMock(ObjectStateGroup::class),
301
            $this->createMock(ObjectStateCreateStruct::class),
302
        ];
303
304
        $objectState = $this->createMock(ObjectState::class);
305
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
306
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
307
308
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
309
        $result = $service->createObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createObjectState() misses a required argument $objectStateCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
310
311
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
312
313
        $this->assertSame($objectState, $result);
314
        $this->assertSame($calledListeners, [
315
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 0],
316
            [ObjectStateEvents::CREATE_OBJECT_STATE, 0],
317
        ]);
318
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
319
    }
320
321 View Code Duplication
    public function testReturnCreateObjectStateResultInBeforeEvents()
322
    {
323
        $traceableEventDispatcher = $this->getEventDispatcher(
324
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE,
325
            ObjectStateEvents::CREATE_OBJECT_STATE
326
        );
327
328
        $parameters = [
329
            $this->createMock(ObjectStateGroup::class),
330
            $this->createMock(ObjectStateCreateStruct::class),
331
        ];
332
333
        $objectState = $this->createMock(ObjectState::class);
334
        $eventObjectState = $this->createMock(ObjectState::class);
335
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
336
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
337
338
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, function (BeforeCreateObjectStateEvent $event) use ($eventObjectState) {
339
            $event->setObjectState($eventObjectState);
340
        }, 10);
341
342
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
343
        $result = $service->createObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createObjectState() misses a required argument $objectStateCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
344
345
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
346
347
        $this->assertSame($eventObjectState, $result);
348
        $this->assertSame($calledListeners, [
349
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 10],
350
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 0],
351
            [ObjectStateEvents::CREATE_OBJECT_STATE, 0],
352
        ]);
353
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
354
    }
355
356 View Code Duplication
    public function testCreateObjectStateStopPropagationInBeforeEvents()
357
    {
358
        $traceableEventDispatcher = $this->getEventDispatcher(
359
            ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE,
360
            ObjectStateEvents::CREATE_OBJECT_STATE
361
        );
362
363
        $parameters = [
364
            $this->createMock(ObjectStateGroup::class),
365
            $this->createMock(ObjectStateCreateStruct::class),
366
        ];
367
368
        $objectState = $this->createMock(ObjectState::class);
369
        $eventObjectState = $this->createMock(ObjectState::class);
370
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
371
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
372
373
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, function (BeforeCreateObjectStateEvent $event) use ($eventObjectState) {
374
            $event->setObjectState($eventObjectState);
375
            $event->stopPropagation();
376
        }, 10);
377
378
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
379
        $result = $service->createObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createObjectState() misses a required argument $objectStateCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
380
381
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
382
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
383
384
        $this->assertSame($eventObjectState, $result);
385
        $this->assertSame($calledListeners, [
386
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 10],
387
        ]);
388
        $this->assertSame($notCalledListeners, [
389
            [ObjectStateEvents::CREATE_OBJECT_STATE, 0],
390
            [ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, 0],
391
        ]);
392
    }
393
394 View Code Duplication
    public function testUpdateObjectStateGroupEvents()
395
    {
396
        $traceableEventDispatcher = $this->getEventDispatcher(
397
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP,
398
            ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP
399
        );
400
401
        $parameters = [
402
            $this->createMock(ObjectStateGroup::class),
403
            $this->createMock(ObjectStateGroupUpdateStruct::class),
404
        ];
405
406
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
407
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
408
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
409
410
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
411
        $result = $service->updateObjectStateGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectStateGroup() misses a required argument $objectStateGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
412
413
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
414
415
        $this->assertSame($updatedObjectStateGroup, $result);
416
        $this->assertSame($calledListeners, [
417
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 0],
418
            [ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP, 0],
419
        ]);
420
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
421
    }
422
423 View Code Duplication
    public function testReturnUpdateObjectStateGroupResultInBeforeEvents()
424
    {
425
        $traceableEventDispatcher = $this->getEventDispatcher(
426
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP,
427
            ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP
428
        );
429
430
        $parameters = [
431
            $this->createMock(ObjectStateGroup::class),
432
            $this->createMock(ObjectStateGroupUpdateStruct::class),
433
        ];
434
435
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
436
        $eventUpdatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
437
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
438
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
439
440
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, function (BeforeUpdateObjectStateGroupEvent $event) use ($eventUpdatedObjectStateGroup) {
441
            $event->setUpdatedObjectStateGroup($eventUpdatedObjectStateGroup);
442
        }, 10);
443
444
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
445
        $result = $service->updateObjectStateGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectStateGroup() misses a required argument $objectStateGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
446
447
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
448
449
        $this->assertSame($eventUpdatedObjectStateGroup, $result);
450
        $this->assertSame($calledListeners, [
451
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 10],
452
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 0],
453
            [ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP, 0],
454
        ]);
455
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
456
    }
457
458 View Code Duplication
    public function testUpdateObjectStateGroupStopPropagationInBeforeEvents()
459
    {
460
        $traceableEventDispatcher = $this->getEventDispatcher(
461
            ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP,
462
            ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP
463
        );
464
465
        $parameters = [
466
            $this->createMock(ObjectStateGroup::class),
467
            $this->createMock(ObjectStateGroupUpdateStruct::class),
468
        ];
469
470
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
471
        $eventUpdatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
472
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
473
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
474
475
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, function (BeforeUpdateObjectStateGroupEvent $event) use ($eventUpdatedObjectStateGroup) {
476
            $event->setUpdatedObjectStateGroup($eventUpdatedObjectStateGroup);
477
            $event->stopPropagation();
478
        }, 10);
479
480
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
481
        $result = $service->updateObjectStateGroup(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateObjectStateGroup() misses a required argument $objectStateGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
482
483
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
484
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
485
486
        $this->assertSame($eventUpdatedObjectStateGroup, $result);
487
        $this->assertSame($calledListeners, [
488
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 10],
489
        ]);
490
        $this->assertSame($notCalledListeners, [
491
            [ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP, 0],
492
            [ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, 0],
493
        ]);
494
    }
495
496
    public function testSetPriorityOfObjectStateEvents()
497
    {
498
        $traceableEventDispatcher = $this->getEventDispatcher(
499
            ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE,
500
            ObjectStateEvents::SET_PRIORITY_OF_OBJECT_STATE
501
        );
502
503
        $parameters = [
504
            $this->createMock(ObjectState::class),
505
            'random_value_5cff79c31cf588.18908758',
506
        ];
507
508
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
509
510
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
511
        $service->setPriorityOfObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setPriorityOfObjectState() misses a required argument $priority.

This check looks for function calls that miss required arguments.

Loading history...
512
513
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
514
515
        $this->assertSame($calledListeners, [
516
            [ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE, 0],
517
            [ObjectStateEvents::SET_PRIORITY_OF_OBJECT_STATE, 0],
518
        ]);
519
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
520
    }
521
522
    public function testSetPriorityOfObjectStateStopPropagationInBeforeEvents()
523
    {
524
        $traceableEventDispatcher = $this->getEventDispatcher(
525
            ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE,
526
            ObjectStateEvents::SET_PRIORITY_OF_OBJECT_STATE
527
        );
528
529
        $parameters = [
530
            $this->createMock(ObjectState::class),
531
            'random_value_5cff79c31cf609.77890182',
532
        ];
533
534
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
535
536
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE, function (BeforeSetPriorityOfObjectStateEvent $event) {
537
            $event->stopPropagation();
538
        }, 10);
539
540
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
541
        $service->setPriorityOfObjectState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setPriorityOfObjectState() misses a required argument $priority.

This check looks for function calls that miss required arguments.

Loading history...
542
543
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
544
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
545
546
        $this->assertSame($calledListeners, [
547
            [ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE, 10],
548
        ]);
549
        $this->assertSame($notCalledListeners, [
550
            [ObjectStateEvents::SET_PRIORITY_OF_OBJECT_STATE, 0],
551
            [ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE, 0],
552
        ]);
553
    }
554
555
    public function testDeleteObjectStateGroupEvents()
556
    {
557
        $traceableEventDispatcher = $this->getEventDispatcher(
558
            ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP,
559
            ObjectStateEvents::DELETE_OBJECT_STATE_GROUP
560
        );
561
562
        $parameters = [
563
            $this->createMock(ObjectStateGroup::class),
564
        ];
565
566
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
567
568
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
569
        $service->deleteObjectStateGroup(...$parameters);
570
571
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
572
573
        $this->assertSame($calledListeners, [
574
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP, 0],
575
            [ObjectStateEvents::DELETE_OBJECT_STATE_GROUP, 0],
576
        ]);
577
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
578
    }
579
580
    public function testDeleteObjectStateGroupStopPropagationInBeforeEvents()
581
    {
582
        $traceableEventDispatcher = $this->getEventDispatcher(
583
            ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP,
584
            ObjectStateEvents::DELETE_OBJECT_STATE_GROUP
585
        );
586
587
        $parameters = [
588
            $this->createMock(ObjectStateGroup::class),
589
        ];
590
591
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
592
593
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP, function (BeforeDeleteObjectStateGroupEvent $event) {
594
            $event->stopPropagation();
595
        }, 10);
596
597
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
598
        $service->deleteObjectStateGroup(...$parameters);
599
600
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
601
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
602
603
        $this->assertSame($calledListeners, [
604
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP, 10],
605
        ]);
606
        $this->assertSame($notCalledListeners, [
607
            [ObjectStateEvents::DELETE_OBJECT_STATE_GROUP, 0],
608
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP, 0],
609
        ]);
610
    }
611
612
    public function testDeleteObjectStateEvents()
613
    {
614
        $traceableEventDispatcher = $this->getEventDispatcher(
615
            ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE,
616
            ObjectStateEvents::DELETE_OBJECT_STATE
617
        );
618
619
        $parameters = [
620
            $this->createMock(ObjectState::class),
621
        ];
622
623
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
624
625
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
626
        $service->deleteObjectState(...$parameters);
627
628
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
629
630
        $this->assertSame($calledListeners, [
631
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE, 0],
632
            [ObjectStateEvents::DELETE_OBJECT_STATE, 0],
633
        ]);
634
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
635
    }
636
637
    public function testDeleteObjectStateStopPropagationInBeforeEvents()
638
    {
639
        $traceableEventDispatcher = $this->getEventDispatcher(
640
            ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE,
641
            ObjectStateEvents::DELETE_OBJECT_STATE
642
        );
643
644
        $parameters = [
645
            $this->createMock(ObjectState::class),
646
        ];
647
648
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
649
650
        $traceableEventDispatcher->addListener(ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE, function (BeforeDeleteObjectStateEvent $event) {
651
            $event->stopPropagation();
652
        }, 10);
653
654
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
655
        $service->deleteObjectState(...$parameters);
656
657
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
658
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
659
660
        $this->assertSame($calledListeners, [
661
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE, 10],
662
        ]);
663
        $this->assertSame($notCalledListeners, [
664
            [ObjectStateEvents::DELETE_OBJECT_STATE, 0],
665
            [ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE, 0],
666
        ]);
667
    }
668
}
669