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

testDeleteObjectStateEvents()   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\ObjectState\BeforeCreateObjectStateEvent as BeforeCreateObjectStateEventInterface;
10
use eZ\Publish\API\Repository\Events\ObjectState\BeforeCreateObjectStateGroupEvent as BeforeCreateObjectStateGroupEventInterface;
11
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateEvent as BeforeDeleteObjectStateEventInterface;
12
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateGroupEvent as BeforeDeleteObjectStateGroupEventInterface;
13
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetContentStateEvent as BeforeSetContentStateEventInterface;
14
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetPriorityOfObjectStateEvent as BeforeSetPriorityOfObjectStateEventInterface;
15
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateEvent as BeforeUpdateObjectStateEventInterface;
16
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateGroupEvent as BeforeUpdateObjectStateGroupEventInterface;
17
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateEvent as CreateObjectStateEventInterface;
18
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateGroupEvent as CreateObjectStateGroupEventInterface;
19
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateEvent as DeleteObjectStateEventInterface;
20
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateGroupEvent as DeleteObjectStateGroupEventInterface;
21
use eZ\Publish\API\Repository\Events\ObjectState\SetContentStateEvent as SetContentStateEventInterface;
22
use eZ\Publish\API\Repository\Events\ObjectState\SetPriorityOfObjectStateEvent as SetPriorityOfObjectStateEventInterface;
23
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateEvent as UpdateObjectStateEventInterface;
24
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateGroupEvent as UpdateObjectStateGroupEventInterface;
25
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface;
26
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
27
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
28
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
29
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
30
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct;
31
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct;
32
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct;
33
use eZ\Publish\Core\Event\ObjectStateService;
34
35
class ObjectStateServiceTest extends AbstractServiceTest
36
{
37 View Code Duplication
    public function testSetContentStateEvents()
38
    {
39
        $traceableEventDispatcher = $this->getEventDispatcher(
40
            BeforeSetContentStateEventInterface::class,
41
            SetContentStateEventInterface::class
42
        );
43
44
        $parameters = [
45
            $this->createMock(ContentInfo::class),
46
            $this->createMock(ObjectStateGroup::class),
47
            $this->createMock(ObjectState::class),
48
        ];
49
50
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
51
52
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
53
        $service->setContentState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setContentState() misses some required arguments starting with $objectStateGroup.
Loading history...
54
55
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
56
57
        $this->assertSame($calledListeners, [
58
            [BeforeSetContentStateEventInterface::class, 0],
59
            [SetContentStateEventInterface::class, 0],
60
        ]);
61
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
62
    }
63
64 View Code Duplication
    public function testSetContentStateStopPropagationInBeforeEvents()
65
    {
66
        $traceableEventDispatcher = $this->getEventDispatcher(
67
            BeforeSetContentStateEventInterface::class,
68
            SetContentStateEventInterface::class
69
        );
70
71
        $parameters = [
72
            $this->createMock(ContentInfo::class),
73
            $this->createMock(ObjectStateGroup::class),
74
            $this->createMock(ObjectState::class),
75
        ];
76
77
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
78
79
        $traceableEventDispatcher->addListener(BeforeSetContentStateEventInterface::class, function (BeforeSetContentStateEventInterface $event) {
80
            $event->stopPropagation();
81
        }, 10);
82
83
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
84
        $service->setContentState(...$parameters);
0 ignored issues
show
Bug introduced by
The call to setContentState() misses some required arguments starting with $objectStateGroup.
Loading history...
85
86
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
87
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
88
89
        $this->assertSame($calledListeners, [
90
            [BeforeSetContentStateEventInterface::class, 10],
91
        ]);
92
        $this->assertSame($notCalledListeners, [
93
            [BeforeSetContentStateEventInterface::class, 0],
94
            [SetContentStateEventInterface::class, 0],
95
        ]);
96
    }
97
98 View Code Duplication
    public function testCreateObjectStateGroupEvents()
99
    {
100
        $traceableEventDispatcher = $this->getEventDispatcher(
101
            BeforeCreateObjectStateGroupEventInterface::class,
102
            CreateObjectStateGroupEventInterface::class
103
        );
104
105
        $parameters = [
106
            $this->createMock(ObjectStateGroupCreateStruct::class),
107
        ];
108
109
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
110
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
111
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
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...
112
113
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
114
        $result = $service->createObjectStateGroup(...$parameters);
115
116
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
117
118
        $this->assertSame($objectStateGroup, $result);
119
        $this->assertSame($calledListeners, [
120
            [BeforeCreateObjectStateGroupEventInterface::class, 0],
121
            [CreateObjectStateGroupEventInterface::class, 0],
122
        ]);
123
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
124
    }
125
126 View Code Duplication
    public function testReturnCreateObjectStateGroupResultInBeforeEvents()
127
    {
128
        $traceableEventDispatcher = $this->getEventDispatcher(
129
            BeforeCreateObjectStateGroupEventInterface::class,
130
            CreateObjectStateGroupEventInterface::class
131
        );
132
133
        $parameters = [
134
            $this->createMock(ObjectStateGroupCreateStruct::class),
135
        ];
136
137
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
138
        $eventObjectStateGroup = $this->createMock(ObjectStateGroup::class);
139
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
140
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
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...
141
142
        $traceableEventDispatcher->addListener(BeforeCreateObjectStateGroupEventInterface::class, function (BeforeCreateObjectStateGroupEventInterface $event) use ($eventObjectStateGroup) {
143
            $event->setObjectStateGroup($eventObjectStateGroup);
144
        }, 10);
145
146
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
147
        $result = $service->createObjectStateGroup(...$parameters);
148
149
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
150
151
        $this->assertSame($eventObjectStateGroup, $result);
152
        $this->assertSame($calledListeners, [
153
            [BeforeCreateObjectStateGroupEventInterface::class, 10],
154
            [BeforeCreateObjectStateGroupEventInterface::class, 0],
155
            [CreateObjectStateGroupEventInterface::class, 0],
156
        ]);
157
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
158
    }
159
160 View Code Duplication
    public function testCreateObjectStateGroupStopPropagationInBeforeEvents()
161
    {
162
        $traceableEventDispatcher = $this->getEventDispatcher(
163
            BeforeCreateObjectStateGroupEventInterface::class,
164
            CreateObjectStateGroupEventInterface::class
165
        );
166
167
        $parameters = [
168
            $this->createMock(ObjectStateGroupCreateStruct::class),
169
        ];
170
171
        $objectStateGroup = $this->createMock(ObjectStateGroup::class);
172
        $eventObjectStateGroup = $this->createMock(ObjectStateGroup::class);
173
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
174
        $innerServiceMock->method('createObjectStateGroup')->willReturn($objectStateGroup);
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...
175
176
        $traceableEventDispatcher->addListener(BeforeCreateObjectStateGroupEventInterface::class, function (BeforeCreateObjectStateGroupEventInterface $event) use ($eventObjectStateGroup) {
177
            $event->setObjectStateGroup($eventObjectStateGroup);
178
            $event->stopPropagation();
179
        }, 10);
180
181
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
182
        $result = $service->createObjectStateGroup(...$parameters);
183
184
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
185
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
186
187
        $this->assertSame($eventObjectStateGroup, $result);
188
        $this->assertSame($calledListeners, [
189
            [BeforeCreateObjectStateGroupEventInterface::class, 10],
190
        ]);
191
        $this->assertSame($notCalledListeners, [
192
            [BeforeCreateObjectStateGroupEventInterface::class, 0],
193
            [CreateObjectStateGroupEventInterface::class, 0],
194
        ]);
195
    }
196
197 View Code Duplication
    public function testUpdateObjectStateEvents()
198
    {
199
        $traceableEventDispatcher = $this->getEventDispatcher(
200
            BeforeUpdateObjectStateEventInterface::class,
201
            UpdateObjectStateEventInterface::class
202
        );
203
204
        $parameters = [
205
            $this->createMock(ObjectState::class),
206
            $this->createMock(ObjectStateUpdateStruct::class),
207
        ];
208
209
        $updatedObjectState = $this->createMock(ObjectState::class);
210
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
211
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
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
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
214
        $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...
215
216
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
217
218
        $this->assertSame($updatedObjectState, $result);
219
        $this->assertSame($calledListeners, [
220
            [BeforeUpdateObjectStateEventInterface::class, 0],
221
            [UpdateObjectStateEventInterface::class, 0],
222
        ]);
223
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
224
    }
225
226 View Code Duplication
    public function testReturnUpdateObjectStateResultInBeforeEvents()
227
    {
228
        $traceableEventDispatcher = $this->getEventDispatcher(
229
            BeforeUpdateObjectStateEventInterface::class,
230
            UpdateObjectStateEventInterface::class
231
        );
232
233
        $parameters = [
234
            $this->createMock(ObjectState::class),
235
            $this->createMock(ObjectStateUpdateStruct::class),
236
        ];
237
238
        $updatedObjectState = $this->createMock(ObjectState::class);
239
        $eventUpdatedObjectState = $this->createMock(ObjectState::class);
240
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
241
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
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...
242
243
        $traceableEventDispatcher->addListener(BeforeUpdateObjectStateEventInterface::class, function (BeforeUpdateObjectStateEventInterface $event) use ($eventUpdatedObjectState) {
244
            $event->setUpdatedObjectState($eventUpdatedObjectState);
245
        }, 10);
246
247
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
248
        $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...
249
250
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
251
252
        $this->assertSame($eventUpdatedObjectState, $result);
253
        $this->assertSame($calledListeners, [
254
            [BeforeUpdateObjectStateEventInterface::class, 10],
255
            [BeforeUpdateObjectStateEventInterface::class, 0],
256
            [UpdateObjectStateEventInterface::class, 0],
257
        ]);
258
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
259
    }
260
261 View Code Duplication
    public function testUpdateObjectStateStopPropagationInBeforeEvents()
262
    {
263
        $traceableEventDispatcher = $this->getEventDispatcher(
264
            BeforeUpdateObjectStateEventInterface::class,
265
            UpdateObjectStateEventInterface::class
266
        );
267
268
        $parameters = [
269
            $this->createMock(ObjectState::class),
270
            $this->createMock(ObjectStateUpdateStruct::class),
271
        ];
272
273
        $updatedObjectState = $this->createMock(ObjectState::class);
274
        $eventUpdatedObjectState = $this->createMock(ObjectState::class);
275
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
276
        $innerServiceMock->method('updateObjectState')->willReturn($updatedObjectState);
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...
277
278
        $traceableEventDispatcher->addListener(BeforeUpdateObjectStateEventInterface::class, function (BeforeUpdateObjectStateEventInterface $event) use ($eventUpdatedObjectState) {
279
            $event->setUpdatedObjectState($eventUpdatedObjectState);
280
            $event->stopPropagation();
281
        }, 10);
282
283
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
284
        $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...
285
286
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
287
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
288
289
        $this->assertSame($eventUpdatedObjectState, $result);
290
        $this->assertSame($calledListeners, [
291
            [BeforeUpdateObjectStateEventInterface::class, 10],
292
        ]);
293
        $this->assertSame($notCalledListeners, [
294
            [BeforeUpdateObjectStateEventInterface::class, 0],
295
            [UpdateObjectStateEventInterface::class, 0],
296
        ]);
297
    }
298
299 View Code Duplication
    public function testCreateObjectStateEvents()
300
    {
301
        $traceableEventDispatcher = $this->getEventDispatcher(
302
            BeforeCreateObjectStateEventInterface::class,
303
            CreateObjectStateEventInterface::class
304
        );
305
306
        $parameters = [
307
            $this->createMock(ObjectStateGroup::class),
308
            $this->createMock(ObjectStateCreateStruct::class),
309
        ];
310
311
        $objectState = $this->createMock(ObjectState::class);
312
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
313
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
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...
314
315
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
316
        $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...
317
318
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
319
320
        $this->assertSame($objectState, $result);
321
        $this->assertSame($calledListeners, [
322
            [BeforeCreateObjectStateEventInterface::class, 0],
323
            [CreateObjectStateEventInterface::class, 0],
324
        ]);
325
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
326
    }
327
328 View Code Duplication
    public function testReturnCreateObjectStateResultInBeforeEvents()
329
    {
330
        $traceableEventDispatcher = $this->getEventDispatcher(
331
            BeforeCreateObjectStateEventInterface::class,
332
            CreateObjectStateEventInterface::class
333
        );
334
335
        $parameters = [
336
            $this->createMock(ObjectStateGroup::class),
337
            $this->createMock(ObjectStateCreateStruct::class),
338
        ];
339
340
        $objectState = $this->createMock(ObjectState::class);
341
        $eventObjectState = $this->createMock(ObjectState::class);
342
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
343
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
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...
344
345
        $traceableEventDispatcher->addListener(BeforeCreateObjectStateEventInterface::class, function (BeforeCreateObjectStateEventInterface $event) use ($eventObjectState) {
346
            $event->setObjectState($eventObjectState);
347
        }, 10);
348
349
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
350
        $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...
351
352
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
353
354
        $this->assertSame($eventObjectState, $result);
355
        $this->assertSame($calledListeners, [
356
            [BeforeCreateObjectStateEventInterface::class, 10],
357
            [BeforeCreateObjectStateEventInterface::class, 0],
358
            [CreateObjectStateEventInterface::class, 0],
359
        ]);
360
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
361
    }
362
363 View Code Duplication
    public function testCreateObjectStateStopPropagationInBeforeEvents()
364
    {
365
        $traceableEventDispatcher = $this->getEventDispatcher(
366
            BeforeCreateObjectStateEventInterface::class,
367
            CreateObjectStateEventInterface::class
368
        );
369
370
        $parameters = [
371
            $this->createMock(ObjectStateGroup::class),
372
            $this->createMock(ObjectStateCreateStruct::class),
373
        ];
374
375
        $objectState = $this->createMock(ObjectState::class);
376
        $eventObjectState = $this->createMock(ObjectState::class);
377
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
378
        $innerServiceMock->method('createObjectState')->willReturn($objectState);
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...
379
380
        $traceableEventDispatcher->addListener(BeforeCreateObjectStateEventInterface::class, function (BeforeCreateObjectStateEventInterface $event) use ($eventObjectState) {
381
            $event->setObjectState($eventObjectState);
382
            $event->stopPropagation();
383
        }, 10);
384
385
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
386
        $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...
387
388
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
389
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
390
391
        $this->assertSame($eventObjectState, $result);
392
        $this->assertSame($calledListeners, [
393
            [BeforeCreateObjectStateEventInterface::class, 10],
394
        ]);
395
        $this->assertSame($notCalledListeners, [
396
            [BeforeCreateObjectStateEventInterface::class, 0],
397
            [CreateObjectStateEventInterface::class, 0],
398
        ]);
399
    }
400
401 View Code Duplication
    public function testUpdateObjectStateGroupEvents()
402
    {
403
        $traceableEventDispatcher = $this->getEventDispatcher(
404
            BeforeUpdateObjectStateGroupEventInterface::class,
405
            UpdateObjectStateGroupEventInterface::class
406
        );
407
408
        $parameters = [
409
            $this->createMock(ObjectStateGroup::class),
410
            $this->createMock(ObjectStateGroupUpdateStruct::class),
411
        ];
412
413
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
414
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
415
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
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...
416
417
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
418
        $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...
419
420
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
421
422
        $this->assertSame($updatedObjectStateGroup, $result);
423
        $this->assertSame($calledListeners, [
424
            [BeforeUpdateObjectStateGroupEventInterface::class, 0],
425
            [UpdateObjectStateGroupEventInterface::class, 0],
426
        ]);
427
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
428
    }
429
430 View Code Duplication
    public function testReturnUpdateObjectStateGroupResultInBeforeEvents()
431
    {
432
        $traceableEventDispatcher = $this->getEventDispatcher(
433
            BeforeUpdateObjectStateGroupEventInterface::class,
434
            UpdateObjectStateGroupEventInterface::class
435
        );
436
437
        $parameters = [
438
            $this->createMock(ObjectStateGroup::class),
439
            $this->createMock(ObjectStateGroupUpdateStruct::class),
440
        ];
441
442
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
443
        $eventUpdatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
444
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
445
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
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...
446
447
        $traceableEventDispatcher->addListener(BeforeUpdateObjectStateGroupEventInterface::class, function (BeforeUpdateObjectStateGroupEventInterface $event) use ($eventUpdatedObjectStateGroup) {
448
            $event->setUpdatedObjectStateGroup($eventUpdatedObjectStateGroup);
449
        }, 10);
450
451
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
452
        $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...
453
454
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
455
456
        $this->assertSame($eventUpdatedObjectStateGroup, $result);
457
        $this->assertSame($calledListeners, [
458
            [BeforeUpdateObjectStateGroupEventInterface::class, 10],
459
            [BeforeUpdateObjectStateGroupEventInterface::class, 0],
460
            [UpdateObjectStateGroupEventInterface::class, 0],
461
        ]);
462
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
463
    }
464
465 View Code Duplication
    public function testUpdateObjectStateGroupStopPropagationInBeforeEvents()
466
    {
467
        $traceableEventDispatcher = $this->getEventDispatcher(
468
            BeforeUpdateObjectStateGroupEventInterface::class,
469
            UpdateObjectStateGroupEventInterface::class
470
        );
471
472
        $parameters = [
473
            $this->createMock(ObjectStateGroup::class),
474
            $this->createMock(ObjectStateGroupUpdateStruct::class),
475
        ];
476
477
        $updatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
478
        $eventUpdatedObjectStateGroup = $this->createMock(ObjectStateGroup::class);
479
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
480
        $innerServiceMock->method('updateObjectStateGroup')->willReturn($updatedObjectStateGroup);
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...
481
482
        $traceableEventDispatcher->addListener(BeforeUpdateObjectStateGroupEventInterface::class, function (BeforeUpdateObjectStateGroupEventInterface $event) use ($eventUpdatedObjectStateGroup) {
483
            $event->setUpdatedObjectStateGroup($eventUpdatedObjectStateGroup);
484
            $event->stopPropagation();
485
        }, 10);
486
487
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
488
        $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...
489
490
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
491
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
492
493
        $this->assertSame($eventUpdatedObjectStateGroup, $result);
494
        $this->assertSame($calledListeners, [
495
            [BeforeUpdateObjectStateGroupEventInterface::class, 10],
496
        ]);
497
        $this->assertSame($notCalledListeners, [
498
            [BeforeUpdateObjectStateGroupEventInterface::class, 0],
499
            [UpdateObjectStateGroupEventInterface::class, 0],
500
        ]);
501
    }
502
503
    public function testSetPriorityOfObjectStateEvents()
504
    {
505
        $traceableEventDispatcher = $this->getEventDispatcher(
506
            BeforeSetPriorityOfObjectStateEventInterface::class,
507
            SetPriorityOfObjectStateEventInterface::class
508
        );
509
510
        $parameters = [
511
            $this->createMock(ObjectState::class),
512
            'random_value_5cff79c31cf588.18908758',
513
        ];
514
515
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
516
517
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
518
        $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...
519
520
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
521
522
        $this->assertSame($calledListeners, [
523
            [BeforeSetPriorityOfObjectStateEventInterface::class, 0],
524
            [SetPriorityOfObjectStateEventInterface::class, 0],
525
        ]);
526
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
527
    }
528
529
    public function testSetPriorityOfObjectStateStopPropagationInBeforeEvents()
530
    {
531
        $traceableEventDispatcher = $this->getEventDispatcher(
532
            BeforeSetPriorityOfObjectStateEventInterface::class,
533
            SetPriorityOfObjectStateEventInterface::class
534
        );
535
536
        $parameters = [
537
            $this->createMock(ObjectState::class),
538
            'random_value_5cff79c31cf609.77890182',
539
        ];
540
541
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
542
543
        $traceableEventDispatcher->addListener(BeforeSetPriorityOfObjectStateEventInterface::class, function (BeforeSetPriorityOfObjectStateEventInterface $event) {
544
            $event->stopPropagation();
545
        }, 10);
546
547
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
548
        $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...
549
550
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
551
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
552
553
        $this->assertSame($calledListeners, [
554
            [BeforeSetPriorityOfObjectStateEventInterface::class, 10],
555
        ]);
556
        $this->assertSame($notCalledListeners, [
557
            [BeforeSetPriorityOfObjectStateEventInterface::class, 0],
558
            [SetPriorityOfObjectStateEventInterface::class, 0],
559
        ]);
560
    }
561
562
    public function testDeleteObjectStateGroupEvents()
563
    {
564
        $traceableEventDispatcher = $this->getEventDispatcher(
565
            BeforeDeleteObjectStateGroupEventInterface::class,
566
            DeleteObjectStateGroupEventInterface::class
567
        );
568
569
        $parameters = [
570
            $this->createMock(ObjectStateGroup::class),
571
        ];
572
573
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
574
575
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
576
        $service->deleteObjectStateGroup(...$parameters);
577
578
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
579
580
        $this->assertSame($calledListeners, [
581
            [BeforeDeleteObjectStateGroupEventInterface::class, 0],
582
            [DeleteObjectStateGroupEventInterface::class, 0],
583
        ]);
584
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
585
    }
586
587
    public function testDeleteObjectStateGroupStopPropagationInBeforeEvents()
588
    {
589
        $traceableEventDispatcher = $this->getEventDispatcher(
590
            BeforeDeleteObjectStateGroupEventInterface::class,
591
            DeleteObjectStateGroupEventInterface::class
592
        );
593
594
        $parameters = [
595
            $this->createMock(ObjectStateGroup::class),
596
        ];
597
598
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
599
600
        $traceableEventDispatcher->addListener(BeforeDeleteObjectStateGroupEventInterface::class, function (BeforeDeleteObjectStateGroupEventInterface $event) {
601
            $event->stopPropagation();
602
        }, 10);
603
604
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
605
        $service->deleteObjectStateGroup(...$parameters);
606
607
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
608
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
609
610
        $this->assertSame($calledListeners, [
611
            [BeforeDeleteObjectStateGroupEventInterface::class, 10],
612
        ]);
613
        $this->assertSame($notCalledListeners, [
614
            [BeforeDeleteObjectStateGroupEventInterface::class, 0],
615
            [DeleteObjectStateGroupEventInterface::class, 0],
616
        ]);
617
    }
618
619
    public function testDeleteObjectStateEvents()
620
    {
621
        $traceableEventDispatcher = $this->getEventDispatcher(
622
            BeforeDeleteObjectStateEventInterface::class,
623
            DeleteObjectStateEventInterface::class
624
        );
625
626
        $parameters = [
627
            $this->createMock(ObjectState::class),
628
        ];
629
630
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
631
632
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
633
        $service->deleteObjectState(...$parameters);
634
635
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
636
637
        $this->assertSame($calledListeners, [
638
            [BeforeDeleteObjectStateEventInterface::class, 0],
639
            [DeleteObjectStateEventInterface::class, 0],
640
        ]);
641
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
642
    }
643
644
    public function testDeleteObjectStateStopPropagationInBeforeEvents()
645
    {
646
        $traceableEventDispatcher = $this->getEventDispatcher(
647
            BeforeDeleteObjectStateEventInterface::class,
648
            DeleteObjectStateEventInterface::class
649
        );
650
651
        $parameters = [
652
            $this->createMock(ObjectState::class),
653
        ];
654
655
        $innerServiceMock = $this->createMock(ObjectStateServiceInterface::class);
656
657
        $traceableEventDispatcher->addListener(BeforeDeleteObjectStateEventInterface::class, function (BeforeDeleteObjectStateEventInterface $event) {
658
            $event->stopPropagation();
659
        }, 10);
660
661
        $service = new ObjectStateService($innerServiceMock, $traceableEventDispatcher);
662
        $service->deleteObjectState(...$parameters);
663
664
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
665
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
666
667
        $this->assertSame($calledListeners, [
668
            [BeforeDeleteObjectStateEventInterface::class, 10],
669
        ]);
670
        $this->assertSame($notCalledListeners, [
671
            [BeforeDeleteObjectStateEventInterface::class, 0],
672
            [DeleteObjectStateEventInterface::class, 0],
673
        ]);
674
    }
675
}
676