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

testDeleteLocationStopPropagationInBeforeEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 31
rs 9.424
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\Location\BeforeCopySubtreeEvent as BeforeCopySubtreeEventInterface;
10
use eZ\Publish\API\Repository\Events\Location\BeforeCreateLocationEvent as BeforeCreateLocationEventInterface;
11
use eZ\Publish\API\Repository\Events\Location\BeforeDeleteLocationEvent as BeforeDeleteLocationEventInterface;
12
use eZ\Publish\API\Repository\Events\Location\BeforeHideLocationEvent as BeforeHideLocationEventInterface;
13
use eZ\Publish\API\Repository\Events\Location\BeforeMoveSubtreeEvent as BeforeMoveSubtreeEventInterface;
14
use eZ\Publish\API\Repository\Events\Location\BeforeSwapLocationEvent as BeforeSwapLocationEventInterface;
15
use eZ\Publish\API\Repository\Events\Location\BeforeUnhideLocationEvent as BeforeUnhideLocationEventInterface;
16
use eZ\Publish\API\Repository\Events\Location\BeforeUpdateLocationEvent as BeforeUpdateLocationEventInterface;
17
use eZ\Publish\API\Repository\Events\Location\CopySubtreeEvent as CopySubtreeEventInterface;
18
use eZ\Publish\API\Repository\Events\Location\CreateLocationEvent as CreateLocationEventInterface;
19
use eZ\Publish\API\Repository\Events\Location\DeleteLocationEvent as DeleteLocationEventInterface;
20
use eZ\Publish\API\Repository\Events\Location\HideLocationEvent as HideLocationEventInterface;
21
use eZ\Publish\API\Repository\Events\Location\MoveSubtreeEvent as MoveSubtreeEventInterface;
22
use eZ\Publish\API\Repository\Events\Location\SwapLocationEvent as SwapLocationEventInterface;
23
use eZ\Publish\API\Repository\Events\Location\UnhideLocationEvent as UnhideLocationEventInterface;
24
use eZ\Publish\API\Repository\Events\Location\UpdateLocationEvent as UpdateLocationEventInterface;
25
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
26
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
27
use eZ\Publish\API\Repository\Values\Content\Location;
28
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
29
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
30
use eZ\Publish\Core\Event\LocationService;
31
32
class LocationServiceTest extends AbstractServiceTest
33
{
34 View Code Duplication
    public function testCopySubtreeEvents()
35
    {
36
        $traceableEventDispatcher = $this->getEventDispatcher(
37
            BeforeCopySubtreeEventInterface::class,
38
            CopySubtreeEventInterface::class
39
        );
40
41
        $parameters = [
42
            $this->createMock(Location::class),
43
            $this->createMock(Location::class),
44
        ];
45
46
        $location = $this->createMock(Location::class);
47
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
48
        $innerServiceMock->method('copySubtree')->willReturn($location);
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...
49
50
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
51
        $result = $service->copySubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copySubtree() misses a required argument $targetParentLocation.

This check looks for function calls that miss required arguments.

Loading history...
52
53
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
54
55
        $this->assertSame($location, $result);
56
        $this->assertSame($calledListeners, [
57
            [BeforeCopySubtreeEventInterface::class, 0],
58
            [CopySubtreeEventInterface::class, 0],
59
        ]);
60
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
61
    }
62
63 View Code Duplication
    public function testReturnCopySubtreeResultInBeforeEvents()
64
    {
65
        $traceableEventDispatcher = $this->getEventDispatcher(
66
            BeforeCopySubtreeEventInterface::class,
67
            CopySubtreeEventInterface::class
68
        );
69
70
        $parameters = [
71
            $this->createMock(Location::class),
72
            $this->createMock(Location::class),
73
        ];
74
75
        $location = $this->createMock(Location::class);
76
        $eventLocation = $this->createMock(Location::class);
77
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
78
        $innerServiceMock->method('copySubtree')->willReturn($location);
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...
79
80
        $traceableEventDispatcher->addListener(BeforeCopySubtreeEventInterface::class, function (BeforeCopySubtreeEventInterface $event) use ($eventLocation) {
81
            $event->setLocation($eventLocation);
82
        }, 10);
83
84
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
85
        $result = $service->copySubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copySubtree() misses a required argument $targetParentLocation.

This check looks for function calls that miss required arguments.

Loading history...
86
87
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
88
89
        $this->assertSame($eventLocation, $result);
90
        $this->assertSame($calledListeners, [
91
            [BeforeCopySubtreeEventInterface::class, 10],
92
            [BeforeCopySubtreeEventInterface::class, 0],
93
            [CopySubtreeEventInterface::class, 0],
94
        ]);
95
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
96
    }
97
98 View Code Duplication
    public function testCopySubtreeStopPropagationInBeforeEvents()
99
    {
100
        $traceableEventDispatcher = $this->getEventDispatcher(
101
            BeforeCopySubtreeEventInterface::class,
102
            CopySubtreeEventInterface::class
103
        );
104
105
        $parameters = [
106
            $this->createMock(Location::class),
107
            $this->createMock(Location::class),
108
        ];
109
110
        $location = $this->createMock(Location::class);
111
        $eventLocation = $this->createMock(Location::class);
112
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
113
        $innerServiceMock->method('copySubtree')->willReturn($location);
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...
114
115
        $traceableEventDispatcher->addListener(BeforeCopySubtreeEventInterface::class, function (BeforeCopySubtreeEventInterface $event) use ($eventLocation) {
116
            $event->setLocation($eventLocation);
117
            $event->stopPropagation();
118
        }, 10);
119
120
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
121
        $result = $service->copySubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copySubtree() misses a required argument $targetParentLocation.

This check looks for function calls that miss required arguments.

Loading history...
122
123
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
124
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
125
126
        $this->assertSame($eventLocation, $result);
127
        $this->assertSame($calledListeners, [
128
            [BeforeCopySubtreeEventInterface::class, 10],
129
        ]);
130
        $this->assertSame($notCalledListeners, [
131
            [BeforeCopySubtreeEventInterface::class, 0],
132
            [CopySubtreeEventInterface::class, 0],
133
        ]);
134
    }
135
136
    public function testDeleteLocationEvents()
137
    {
138
        $traceableEventDispatcher = $this->getEventDispatcher(
139
            BeforeDeleteLocationEventInterface::class,
140
            DeleteLocationEventInterface::class
141
        );
142
143
        $parameters = [
144
            $this->createMock(Location::class),
145
        ];
146
147
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
148
149
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
150
        $service->deleteLocation(...$parameters);
151
152
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
153
154
        $this->assertSame($calledListeners, [
155
            [BeforeDeleteLocationEventInterface::class, 0],
156
            [DeleteLocationEventInterface::class, 0],
157
        ]);
158
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
159
    }
160
161
    public function testDeleteLocationStopPropagationInBeforeEvents()
162
    {
163
        $traceableEventDispatcher = $this->getEventDispatcher(
164
            BeforeDeleteLocationEventInterface::class,
165
            DeleteLocationEventInterface::class
166
        );
167
168
        $parameters = [
169
            $this->createMock(Location::class),
170
        ];
171
172
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
173
174
        $traceableEventDispatcher->addListener(BeforeDeleteLocationEventInterface::class, function (BeforeDeleteLocationEventInterface $event) {
175
            $event->stopPropagation();
176
        }, 10);
177
178
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
179
        $service->deleteLocation(...$parameters);
180
181
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
182
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
183
184
        $this->assertSame($calledListeners, [
185
            [BeforeDeleteLocationEventInterface::class, 10],
186
        ]);
187
        $this->assertSame($notCalledListeners, [
188
            [BeforeDeleteLocationEventInterface::class, 0],
189
            [DeleteLocationEventInterface::class, 0],
190
        ]);
191
    }
192
193 View Code Duplication
    public function testUnhideLocationEvents()
194
    {
195
        $traceableEventDispatcher = $this->getEventDispatcher(
196
            BeforeUnhideLocationEventInterface::class,
197
            UnhideLocationEventInterface::class
198
        );
199
200
        $parameters = [
201
            $this->createMock(Location::class),
202
        ];
203
204
        $revealedLocation = $this->createMock(Location::class);
205
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
206
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
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...
207
208
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
209
        $result = $service->unhideLocation(...$parameters);
210
211
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
212
213
        $this->assertSame($revealedLocation, $result);
214
        $this->assertSame($calledListeners, [
215
            [BeforeUnhideLocationEventInterface::class, 0],
216
            [UnhideLocationEventInterface::class, 0],
217
        ]);
218
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
219
    }
220
221 View Code Duplication
    public function testReturnUnhideLocationResultInBeforeEvents()
222
    {
223
        $traceableEventDispatcher = $this->getEventDispatcher(
224
            BeforeUnhideLocationEventInterface::class,
225
            UnhideLocationEventInterface::class
226
        );
227
228
        $parameters = [
229
            $this->createMock(Location::class),
230
        ];
231
232
        $revealedLocation = $this->createMock(Location::class);
233
        $eventRevealedLocation = $this->createMock(Location::class);
234
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
235
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
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...
236
237
        $traceableEventDispatcher->addListener(BeforeUnhideLocationEventInterface::class, function (BeforeUnhideLocationEventInterface $event) use ($eventRevealedLocation) {
238
            $event->setRevealedLocation($eventRevealedLocation);
239
        }, 10);
240
241
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
242
        $result = $service->unhideLocation(...$parameters);
243
244
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
245
246
        $this->assertSame($eventRevealedLocation, $result);
247
        $this->assertSame($calledListeners, [
248
            [BeforeUnhideLocationEventInterface::class, 10],
249
            [BeforeUnhideLocationEventInterface::class, 0],
250
            [UnhideLocationEventInterface::class, 0],
251
        ]);
252
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
253
    }
254
255 View Code Duplication
    public function testUnhideLocationStopPropagationInBeforeEvents()
256
    {
257
        $traceableEventDispatcher = $this->getEventDispatcher(
258
            BeforeUnhideLocationEventInterface::class,
259
            UnhideLocationEventInterface::class
260
        );
261
262
        $parameters = [
263
            $this->createMock(Location::class),
264
        ];
265
266
        $revealedLocation = $this->createMock(Location::class);
267
        $eventRevealedLocation = $this->createMock(Location::class);
268
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
269
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
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...
270
271
        $traceableEventDispatcher->addListener(BeforeUnhideLocationEventInterface::class, function (BeforeUnhideLocationEventInterface $event) use ($eventRevealedLocation) {
272
            $event->setRevealedLocation($eventRevealedLocation);
273
            $event->stopPropagation();
274
        }, 10);
275
276
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
277
        $result = $service->unhideLocation(...$parameters);
278
279
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
280
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
281
282
        $this->assertSame($eventRevealedLocation, $result);
283
        $this->assertSame($calledListeners, [
284
            [BeforeUnhideLocationEventInterface::class, 10],
285
        ]);
286
        $this->assertSame($notCalledListeners, [
287
            [BeforeUnhideLocationEventInterface::class, 0],
288
            [UnhideLocationEventInterface::class, 0],
289
        ]);
290
    }
291
292 View Code Duplication
    public function testHideLocationEvents()
293
    {
294
        $traceableEventDispatcher = $this->getEventDispatcher(
295
            BeforeHideLocationEventInterface::class,
296
            HideLocationEventInterface::class
297
        );
298
299
        $parameters = [
300
            $this->createMock(Location::class),
301
        ];
302
303
        $hiddenLocation = $this->createMock(Location::class);
304
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
305
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
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...
306
307
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
308
        $result = $service->hideLocation(...$parameters);
309
310
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
311
312
        $this->assertSame($hiddenLocation, $result);
313
        $this->assertSame($calledListeners, [
314
            [BeforeHideLocationEventInterface::class, 0],
315
            [HideLocationEventInterface::class, 0],
316
        ]);
317
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
318
    }
319
320 View Code Duplication
    public function testReturnHideLocationResultInBeforeEvents()
321
    {
322
        $traceableEventDispatcher = $this->getEventDispatcher(
323
            BeforeHideLocationEventInterface::class,
324
            HideLocationEventInterface::class
325
        );
326
327
        $parameters = [
328
            $this->createMock(Location::class),
329
        ];
330
331
        $hiddenLocation = $this->createMock(Location::class);
332
        $eventHiddenLocation = $this->createMock(Location::class);
333
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
334
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
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...
335
336
        $traceableEventDispatcher->addListener(BeforeHideLocationEventInterface::class, function (BeforeHideLocationEventInterface $event) use ($eventHiddenLocation) {
337
            $event->setHiddenLocation($eventHiddenLocation);
338
        }, 10);
339
340
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
341
        $result = $service->hideLocation(...$parameters);
342
343
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
344
345
        $this->assertSame($eventHiddenLocation, $result);
346
        $this->assertSame($calledListeners, [
347
            [BeforeHideLocationEventInterface::class, 10],
348
            [BeforeHideLocationEventInterface::class, 0],
349
            [HideLocationEventInterface::class, 0],
350
        ]);
351
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
352
    }
353
354 View Code Duplication
    public function testHideLocationStopPropagationInBeforeEvents()
355
    {
356
        $traceableEventDispatcher = $this->getEventDispatcher(
357
            BeforeHideLocationEventInterface::class,
358
            HideLocationEventInterface::class
359
        );
360
361
        $parameters = [
362
            $this->createMock(Location::class),
363
        ];
364
365
        $hiddenLocation = $this->createMock(Location::class);
366
        $eventHiddenLocation = $this->createMock(Location::class);
367
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
368
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
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...
369
370
        $traceableEventDispatcher->addListener(BeforeHideLocationEventInterface::class, function (BeforeHideLocationEventInterface $event) use ($eventHiddenLocation) {
371
            $event->setHiddenLocation($eventHiddenLocation);
372
            $event->stopPropagation();
373
        }, 10);
374
375
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
376
        $result = $service->hideLocation(...$parameters);
377
378
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
379
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
380
381
        $this->assertSame($eventHiddenLocation, $result);
382
        $this->assertSame($calledListeners, [
383
            [BeforeHideLocationEventInterface::class, 10],
384
        ]);
385
        $this->assertSame($notCalledListeners, [
386
            [BeforeHideLocationEventInterface::class, 0],
387
            [HideLocationEventInterface::class, 0],
388
        ]);
389
    }
390
391
    public function testSwapLocationEvents()
392
    {
393
        $traceableEventDispatcher = $this->getEventDispatcher(
394
            BeforeSwapLocationEventInterface::class,
395
            SwapLocationEventInterface::class
396
        );
397
398
        $parameters = [
399
            $this->createMock(Location::class),
400
            $this->createMock(Location::class),
401
        ];
402
403
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
404
405
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
406
        $service->swapLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to swapLocation() misses a required argument $location2.

This check looks for function calls that miss required arguments.

Loading history...
407
408
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
409
410
        $this->assertSame($calledListeners, [
411
            [BeforeSwapLocationEventInterface::class, 0],
412
            [SwapLocationEventInterface::class, 0],
413
        ]);
414
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
415
    }
416
417 View Code Duplication
    public function testSwapLocationStopPropagationInBeforeEvents()
418
    {
419
        $traceableEventDispatcher = $this->getEventDispatcher(
420
            BeforeSwapLocationEventInterface::class,
421
            SwapLocationEventInterface::class
422
        );
423
424
        $parameters = [
425
            $this->createMock(Location::class),
426
            $this->createMock(Location::class),
427
        ];
428
429
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
430
431
        $traceableEventDispatcher->addListener(BeforeSwapLocationEventInterface::class, function (BeforeSwapLocationEventInterface $event) {
432
            $event->stopPropagation();
433
        }, 10);
434
435
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
436
        $service->swapLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to swapLocation() misses a required argument $location2.

This check looks for function calls that miss required arguments.

Loading history...
437
438
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
439
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
440
441
        $this->assertSame($calledListeners, [
442
            [BeforeSwapLocationEventInterface::class, 10],
443
        ]);
444
        $this->assertSame($notCalledListeners, [
445
            [BeforeSwapLocationEventInterface::class, 0],
446
            [SwapLocationEventInterface::class, 0],
447
        ]);
448
    }
449
450
    public function testMoveSubtreeEvents()
451
    {
452
        $traceableEventDispatcher = $this->getEventDispatcher(
453
            BeforeMoveSubtreeEventInterface::class,
454
            MoveSubtreeEventInterface::class
455
        );
456
457
        $parameters = [
458
            $this->createMock(Location::class),
459
            $this->createMock(Location::class),
460
        ];
461
462
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
463
464
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
465
        $service->moveSubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to moveSubtree() misses a required argument $newParentLocation.

This check looks for function calls that miss required arguments.

Loading history...
466
467
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
468
469
        $this->assertSame($calledListeners, [
470
            [BeforeMoveSubtreeEventInterface::class, 0],
471
            [MoveSubtreeEventInterface::class, 0],
472
        ]);
473
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
474
    }
475
476 View Code Duplication
    public function testMoveSubtreeStopPropagationInBeforeEvents()
477
    {
478
        $traceableEventDispatcher = $this->getEventDispatcher(
479
            BeforeMoveSubtreeEventInterface::class,
480
            MoveSubtreeEventInterface::class
481
        );
482
483
        $parameters = [
484
            $this->createMock(Location::class),
485
            $this->createMock(Location::class),
486
        ];
487
488
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
489
490
        $traceableEventDispatcher->addListener(BeforeMoveSubtreeEventInterface::class, function (BeforeMoveSubtreeEventInterface $event) {
491
            $event->stopPropagation();
492
        }, 10);
493
494
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
495
        $service->moveSubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to moveSubtree() misses a required argument $newParentLocation.

This check looks for function calls that miss required arguments.

Loading history...
496
497
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
498
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
499
500
        $this->assertSame($calledListeners, [
501
            [BeforeMoveSubtreeEventInterface::class, 10],
502
        ]);
503
        $this->assertSame($notCalledListeners, [
504
            [BeforeMoveSubtreeEventInterface::class, 0],
505
            [MoveSubtreeEventInterface::class, 0],
506
        ]);
507
    }
508
509 View Code Duplication
    public function testUpdateLocationEvents()
510
    {
511
        $traceableEventDispatcher = $this->getEventDispatcher(
512
            BeforeUpdateLocationEventInterface::class,
513
            UpdateLocationEventInterface::class
514
        );
515
516
        $parameters = [
517
            $this->createMock(Location::class),
518
            $this->createMock(LocationUpdateStruct::class),
519
        ];
520
521
        $updatedLocation = $this->createMock(Location::class);
522
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
523
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
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...
524
525
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
526
        $result = $service->updateLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateLocation() misses a required argument $locationUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
527
528
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
529
530
        $this->assertSame($updatedLocation, $result);
531
        $this->assertSame($calledListeners, [
532
            [BeforeUpdateLocationEventInterface::class, 0],
533
            [UpdateLocationEventInterface::class, 0],
534
        ]);
535
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
536
    }
537
538 View Code Duplication
    public function testReturnUpdateLocationResultInBeforeEvents()
539
    {
540
        $traceableEventDispatcher = $this->getEventDispatcher(
541
            BeforeUpdateLocationEventInterface::class,
542
            UpdateLocationEventInterface::class
543
        );
544
545
        $parameters = [
546
            $this->createMock(Location::class),
547
            $this->createMock(LocationUpdateStruct::class),
548
        ];
549
550
        $updatedLocation = $this->createMock(Location::class);
551
        $eventUpdatedLocation = $this->createMock(Location::class);
552
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
553
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
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...
554
555
        $traceableEventDispatcher->addListener(BeforeUpdateLocationEventInterface::class, function (BeforeUpdateLocationEventInterface $event) use ($eventUpdatedLocation) {
556
            $event->setUpdatedLocation($eventUpdatedLocation);
557
        }, 10);
558
559
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
560
        $result = $service->updateLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateLocation() misses a required argument $locationUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
561
562
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
563
564
        $this->assertSame($eventUpdatedLocation, $result);
565
        $this->assertSame($calledListeners, [
566
            [BeforeUpdateLocationEventInterface::class, 10],
567
            [BeforeUpdateLocationEventInterface::class, 0],
568
            [UpdateLocationEventInterface::class, 0],
569
        ]);
570
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
571
    }
572
573 View Code Duplication
    public function testUpdateLocationStopPropagationInBeforeEvents()
574
    {
575
        $traceableEventDispatcher = $this->getEventDispatcher(
576
            BeforeUpdateLocationEventInterface::class,
577
            UpdateLocationEventInterface::class
578
        );
579
580
        $parameters = [
581
            $this->createMock(Location::class),
582
            $this->createMock(LocationUpdateStruct::class),
583
        ];
584
585
        $updatedLocation = $this->createMock(Location::class);
586
        $eventUpdatedLocation = $this->createMock(Location::class);
587
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
588
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
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...
589
590
        $traceableEventDispatcher->addListener(BeforeUpdateLocationEventInterface::class, function (BeforeUpdateLocationEventInterface $event) use ($eventUpdatedLocation) {
591
            $event->setUpdatedLocation($eventUpdatedLocation);
592
            $event->stopPropagation();
593
        }, 10);
594
595
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
596
        $result = $service->updateLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateLocation() misses a required argument $locationUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
597
598
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
599
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
600
601
        $this->assertSame($eventUpdatedLocation, $result);
602
        $this->assertSame($calledListeners, [
603
            [BeforeUpdateLocationEventInterface::class, 10],
604
        ]);
605
        $this->assertSame($notCalledListeners, [
606
            [BeforeUpdateLocationEventInterface::class, 0],
607
            [UpdateLocationEventInterface::class, 0],
608
        ]);
609
    }
610
611 View Code Duplication
    public function testCreateLocationEvents()
612
    {
613
        $traceableEventDispatcher = $this->getEventDispatcher(
614
            BeforeCreateLocationEventInterface::class,
615
            CreateLocationEventInterface::class
616
        );
617
618
        $parameters = [
619
            $this->createMock(ContentInfo::class),
620
            $this->createMock(LocationCreateStruct::class),
621
        ];
622
623
        $location = $this->createMock(Location::class);
624
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
625
        $innerServiceMock->method('createLocation')->willReturn($location);
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...
626
627
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
628
        $result = $service->createLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createLocation() misses a required argument $locationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
629
630
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
631
632
        $this->assertSame($location, $result);
633
        $this->assertSame($calledListeners, [
634
            [BeforeCreateLocationEventInterface::class, 0],
635
            [CreateLocationEventInterface::class, 0],
636
        ]);
637
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
638
    }
639
640 View Code Duplication
    public function testReturnCreateLocationResultInBeforeEvents()
641
    {
642
        $traceableEventDispatcher = $this->getEventDispatcher(
643
            BeforeCreateLocationEventInterface::class,
644
            CreateLocationEventInterface::class
645
        );
646
647
        $parameters = [
648
            $this->createMock(ContentInfo::class),
649
            $this->createMock(LocationCreateStruct::class),
650
        ];
651
652
        $location = $this->createMock(Location::class);
653
        $eventLocation = $this->createMock(Location::class);
654
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
655
        $innerServiceMock->method('createLocation')->willReturn($location);
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...
656
657
        $traceableEventDispatcher->addListener(BeforeCreateLocationEventInterface::class, function (BeforeCreateLocationEventInterface $event) use ($eventLocation) {
658
            $event->setLocation($eventLocation);
659
        }, 10);
660
661
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
662
        $result = $service->createLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createLocation() misses a required argument $locationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
663
664
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
665
666
        $this->assertSame($eventLocation, $result);
667
        $this->assertSame($calledListeners, [
668
            [BeforeCreateLocationEventInterface::class, 10],
669
            [BeforeCreateLocationEventInterface::class, 0],
670
            [CreateLocationEventInterface::class, 0],
671
        ]);
672
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
673
    }
674
675 View Code Duplication
    public function testCreateLocationStopPropagationInBeforeEvents()
676
    {
677
        $traceableEventDispatcher = $this->getEventDispatcher(
678
            BeforeCreateLocationEventInterface::class,
679
            CreateLocationEventInterface::class
680
        );
681
682
        $parameters = [
683
            $this->createMock(ContentInfo::class),
684
            $this->createMock(LocationCreateStruct::class),
685
        ];
686
687
        $location = $this->createMock(Location::class);
688
        $eventLocation = $this->createMock(Location::class);
689
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
690
        $innerServiceMock->method('createLocation')->willReturn($location);
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...
691
692
        $traceableEventDispatcher->addListener(BeforeCreateLocationEventInterface::class, function (BeforeCreateLocationEventInterface $event) use ($eventLocation) {
693
            $event->setLocation($eventLocation);
694
            $event->stopPropagation();
695
        }, 10);
696
697
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
698
        $result = $service->createLocation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to createLocation() misses a required argument $locationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
699
700
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
701
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
702
703
        $this->assertSame($eventLocation, $result);
704
        $this->assertSame($calledListeners, [
705
            [BeforeCreateLocationEventInterface::class, 10],
706
        ]);
707
        $this->assertSame($notCalledListeners, [
708
            [BeforeCreateLocationEventInterface::class, 0],
709
            [CreateLocationEventInterface::class, 0],
710
        ]);
711
    }
712
}
713