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

LocationServiceTest   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 681
Duplicated Lines 53.01 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
dl 361
loc 681
rs 9.919
c 0
b 0
f 0
wmc 21
lcom 1
cbo 11

21 Methods

Rating   Name   Duplication   Size   Complexity  
A testCopySubtreeEvents() 28 28 1
A testReturnCopySubtreeResultInBeforeEvents() 34 34 1
A testCopySubtreeStopPropagationInBeforeEvents() 37 37 1
A testDeleteLocationEvents() 0 24 1
A testDeleteLocationStopPropagationInBeforeEvents() 0 31 1
A testUnhideLocationEvents() 0 27 1
A testReturnUnhideLocationResultInBeforeEvents() 0 33 1
A testUnhideLocationStopPropagationInBeforeEvents() 0 36 1
A testHideLocationEvents() 0 27 1
A testReturnHideLocationResultInBeforeEvents() 0 33 1
A testHideLocationStopPropagationInBeforeEvents() 0 36 1
A testSwapLocationEvents() 0 25 1
A testSwapLocationStopPropagationInBeforeEvents() 32 32 1
A testMoveSubtreeEvents() 0 25 1
A testMoveSubtreeStopPropagationInBeforeEvents() 32 32 1
A testUpdateLocationEvents() 28 28 1
A testReturnUpdateLocationResultInBeforeEvents() 34 34 1
A testUpdateLocationStopPropagationInBeforeEvents() 37 37 1
A testCreateLocationEvents() 28 28 1
A testReturnCreateLocationResultInBeforeEvents() 34 34 1
A testCreateLocationStopPropagationInBeforeEvents() 37 37 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\LocationService as LocationServiceInterface;
10
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
11
use eZ\Publish\API\Repository\Values\Content\Location;
12
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
13
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
14
use eZ\Publish\Core\Event\LocationService;
15
use eZ\Publish\Core\Event\Location\BeforeCopySubtreeEvent;
16
use eZ\Publish\Core\Event\Location\BeforeCreateLocationEvent;
17
use eZ\Publish\Core\Event\Location\BeforeDeleteLocationEvent;
18
use eZ\Publish\Core\Event\Location\BeforeHideLocationEvent;
19
use eZ\Publish\Core\Event\Location\BeforeMoveSubtreeEvent;
20
use eZ\Publish\Core\Event\Location\BeforeSwapLocationEvent;
21
use eZ\Publish\Core\Event\Location\BeforeUnhideLocationEvent;
22
use eZ\Publish\Core\Event\Location\BeforeUpdateLocationEvent;
23
use eZ\Publish\Core\Event\Location\LocationEvents;
24
25
class LocationServiceTest extends AbstractServiceTest
26
{
27 View Code Duplication
    public function testCopySubtreeEvents()
28
    {
29
        $traceableEventDispatcher = $this->getEventDispatcher(
30
            LocationEvents::BEFORE_COPY_SUBTREE,
31
            LocationEvents::COPY_SUBTREE
32
        );
33
34
        $parameters = [
35
            $this->createMock(Location::class),
36
            $this->createMock(Location::class),
37
        ];
38
39
        $location = $this->createMock(Location::class);
40
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
41
        $innerServiceMock->method('copySubtree')->willReturn($location);
42
43
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
44
        $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...
45
46
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
47
48
        $this->assertSame($location, $result);
49
        $this->assertSame($calledListeners, [
50
            [LocationEvents::BEFORE_COPY_SUBTREE, 0],
51
            [LocationEvents::COPY_SUBTREE, 0],
52
        ]);
53
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
54
    }
55
56 View Code Duplication
    public function testReturnCopySubtreeResultInBeforeEvents()
57
    {
58
        $traceableEventDispatcher = $this->getEventDispatcher(
59
            LocationEvents::BEFORE_COPY_SUBTREE,
60
            LocationEvents::COPY_SUBTREE
61
        );
62
63
        $parameters = [
64
            $this->createMock(Location::class),
65
            $this->createMock(Location::class),
66
        ];
67
68
        $location = $this->createMock(Location::class);
69
        $eventLocation = $this->createMock(Location::class);
70
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
71
        $innerServiceMock->method('copySubtree')->willReturn($location);
72
73
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_COPY_SUBTREE, function (BeforeCopySubtreeEvent $event) use ($eventLocation) {
74
            $event->setLocation($eventLocation);
75
        }, 10);
76
77
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
78
        $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...
79
80
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
81
82
        $this->assertSame($eventLocation, $result);
83
        $this->assertSame($calledListeners, [
84
            [LocationEvents::BEFORE_COPY_SUBTREE, 10],
85
            [LocationEvents::BEFORE_COPY_SUBTREE, 0],
86
            [LocationEvents::COPY_SUBTREE, 0],
87
        ]);
88
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
89
    }
90
91 View Code Duplication
    public function testCopySubtreeStopPropagationInBeforeEvents()
92
    {
93
        $traceableEventDispatcher = $this->getEventDispatcher(
94
            LocationEvents::BEFORE_COPY_SUBTREE,
95
            LocationEvents::COPY_SUBTREE
96
        );
97
98
        $parameters = [
99
            $this->createMock(Location::class),
100
            $this->createMock(Location::class),
101
        ];
102
103
        $location = $this->createMock(Location::class);
104
        $eventLocation = $this->createMock(Location::class);
105
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
106
        $innerServiceMock->method('copySubtree')->willReturn($location);
107
108
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_COPY_SUBTREE, function (BeforeCopySubtreeEvent $event) use ($eventLocation) {
109
            $event->setLocation($eventLocation);
110
            $event->stopPropagation();
111
        }, 10);
112
113
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
114
        $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...
115
116
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
117
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
118
119
        $this->assertSame($eventLocation, $result);
120
        $this->assertSame($calledListeners, [
121
            [LocationEvents::BEFORE_COPY_SUBTREE, 10],
122
        ]);
123
        $this->assertSame($notCalledListeners, [
124
            [LocationEvents::COPY_SUBTREE, 0],
125
            [LocationEvents::BEFORE_COPY_SUBTREE, 0],
126
        ]);
127
    }
128
129
    public function testDeleteLocationEvents()
130
    {
131
        $traceableEventDispatcher = $this->getEventDispatcher(
132
            LocationEvents::BEFORE_DELETE_LOCATION,
133
            LocationEvents::DELETE_LOCATION
134
        );
135
136
        $parameters = [
137
            $this->createMock(Location::class),
138
        ];
139
140
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
141
142
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
143
        $service->deleteLocation(...$parameters);
144
145
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
146
147
        $this->assertSame($calledListeners, [
148
            [LocationEvents::BEFORE_DELETE_LOCATION, 0],
149
            [LocationEvents::DELETE_LOCATION, 0],
150
        ]);
151
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
152
    }
153
154
    public function testDeleteLocationStopPropagationInBeforeEvents()
155
    {
156
        $traceableEventDispatcher = $this->getEventDispatcher(
157
            LocationEvents::BEFORE_DELETE_LOCATION,
158
            LocationEvents::DELETE_LOCATION
159
        );
160
161
        $parameters = [
162
            $this->createMock(Location::class),
163
        ];
164
165
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
166
167
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_DELETE_LOCATION, function (BeforeDeleteLocationEvent $event) {
168
            $event->stopPropagation();
169
        }, 10);
170
171
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
172
        $service->deleteLocation(...$parameters);
173
174
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
175
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
176
177
        $this->assertSame($calledListeners, [
178
            [LocationEvents::BEFORE_DELETE_LOCATION, 10],
179
        ]);
180
        $this->assertSame($notCalledListeners, [
181
            [LocationEvents::DELETE_LOCATION, 0],
182
            [LocationEvents::BEFORE_DELETE_LOCATION, 0],
183
        ]);
184
    }
185
186
    public function testUnhideLocationEvents()
187
    {
188
        $traceableEventDispatcher = $this->getEventDispatcher(
189
            LocationEvents::BEFORE_UNHIDE_LOCATION,
190
            LocationEvents::UNHIDE_LOCATION
191
        );
192
193
        $parameters = [
194
            $this->createMock(Location::class),
195
        ];
196
197
        $revealedLocation = $this->createMock(Location::class);
198
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
199
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
200
201
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
202
        $result = $service->unhideLocation(...$parameters);
203
204
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
205
206
        $this->assertSame($revealedLocation, $result);
207
        $this->assertSame($calledListeners, [
208
            [LocationEvents::BEFORE_UNHIDE_LOCATION, 0],
209
            [LocationEvents::UNHIDE_LOCATION, 0],
210
        ]);
211
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
212
    }
213
214
    public function testReturnUnhideLocationResultInBeforeEvents()
215
    {
216
        $traceableEventDispatcher = $this->getEventDispatcher(
217
            LocationEvents::BEFORE_UNHIDE_LOCATION,
218
            LocationEvents::UNHIDE_LOCATION
219
        );
220
221
        $parameters = [
222
            $this->createMock(Location::class),
223
        ];
224
225
        $revealedLocation = $this->createMock(Location::class);
226
        $eventRevealedLocation = $this->createMock(Location::class);
227
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
228
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
229
230
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_UNHIDE_LOCATION, function (BeforeUnhideLocationEvent $event) use ($eventRevealedLocation) {
231
            $event->setRevealedLocation($eventRevealedLocation);
232
        }, 10);
233
234
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
235
        $result = $service->unhideLocation(...$parameters);
236
237
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
238
239
        $this->assertSame($eventRevealedLocation, $result);
240
        $this->assertSame($calledListeners, [
241
            [LocationEvents::BEFORE_UNHIDE_LOCATION, 10],
242
            [LocationEvents::BEFORE_UNHIDE_LOCATION, 0],
243
            [LocationEvents::UNHIDE_LOCATION, 0],
244
        ]);
245
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
246
    }
247
248
    public function testUnhideLocationStopPropagationInBeforeEvents()
249
    {
250
        $traceableEventDispatcher = $this->getEventDispatcher(
251
            LocationEvents::BEFORE_UNHIDE_LOCATION,
252
            LocationEvents::UNHIDE_LOCATION
253
        );
254
255
        $parameters = [
256
            $this->createMock(Location::class),
257
        ];
258
259
        $revealedLocation = $this->createMock(Location::class);
260
        $eventRevealedLocation = $this->createMock(Location::class);
261
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
262
        $innerServiceMock->method('unhideLocation')->willReturn($revealedLocation);
263
264
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_UNHIDE_LOCATION, function (BeforeUnhideLocationEvent $event) use ($eventRevealedLocation) {
265
            $event->setRevealedLocation($eventRevealedLocation);
266
            $event->stopPropagation();
267
        }, 10);
268
269
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
270
        $result = $service->unhideLocation(...$parameters);
271
272
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
273
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
274
275
        $this->assertSame($eventRevealedLocation, $result);
276
        $this->assertSame($calledListeners, [
277
            [LocationEvents::BEFORE_UNHIDE_LOCATION, 10],
278
        ]);
279
        $this->assertSame($notCalledListeners, [
280
            [LocationEvents::UNHIDE_LOCATION, 0],
281
            [LocationEvents::BEFORE_UNHIDE_LOCATION, 0],
282
        ]);
283
    }
284
285
    public function testHideLocationEvents()
286
    {
287
        $traceableEventDispatcher = $this->getEventDispatcher(
288
            LocationEvents::BEFORE_HIDE_LOCATION,
289
            LocationEvents::HIDE_LOCATION
290
        );
291
292
        $parameters = [
293
            $this->createMock(Location::class),
294
        ];
295
296
        $hiddenLocation = $this->createMock(Location::class);
297
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
298
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
299
300
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
301
        $result = $service->hideLocation(...$parameters);
302
303
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
304
305
        $this->assertSame($hiddenLocation, $result);
306
        $this->assertSame($calledListeners, [
307
            [LocationEvents::BEFORE_HIDE_LOCATION, 0],
308
            [LocationEvents::HIDE_LOCATION, 0],
309
        ]);
310
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
311
    }
312
313
    public function testReturnHideLocationResultInBeforeEvents()
314
    {
315
        $traceableEventDispatcher = $this->getEventDispatcher(
316
            LocationEvents::BEFORE_HIDE_LOCATION,
317
            LocationEvents::HIDE_LOCATION
318
        );
319
320
        $parameters = [
321
            $this->createMock(Location::class),
322
        ];
323
324
        $hiddenLocation = $this->createMock(Location::class);
325
        $eventHiddenLocation = $this->createMock(Location::class);
326
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
327
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
328
329
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_HIDE_LOCATION, function (BeforeHideLocationEvent $event) use ($eventHiddenLocation) {
330
            $event->setHiddenLocation($eventHiddenLocation);
331
        }, 10);
332
333
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
334
        $result = $service->hideLocation(...$parameters);
335
336
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
337
338
        $this->assertSame($eventHiddenLocation, $result);
339
        $this->assertSame($calledListeners, [
340
            [LocationEvents::BEFORE_HIDE_LOCATION, 10],
341
            [LocationEvents::BEFORE_HIDE_LOCATION, 0],
342
            [LocationEvents::HIDE_LOCATION, 0],
343
        ]);
344
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
345
    }
346
347
    public function testHideLocationStopPropagationInBeforeEvents()
348
    {
349
        $traceableEventDispatcher = $this->getEventDispatcher(
350
            LocationEvents::BEFORE_HIDE_LOCATION,
351
            LocationEvents::HIDE_LOCATION
352
        );
353
354
        $parameters = [
355
            $this->createMock(Location::class),
356
        ];
357
358
        $hiddenLocation = $this->createMock(Location::class);
359
        $eventHiddenLocation = $this->createMock(Location::class);
360
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
361
        $innerServiceMock->method('hideLocation')->willReturn($hiddenLocation);
362
363
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_HIDE_LOCATION, function (BeforeHideLocationEvent $event) use ($eventHiddenLocation) {
364
            $event->setHiddenLocation($eventHiddenLocation);
365
            $event->stopPropagation();
366
        }, 10);
367
368
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
369
        $result = $service->hideLocation(...$parameters);
370
371
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
372
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
373
374
        $this->assertSame($eventHiddenLocation, $result);
375
        $this->assertSame($calledListeners, [
376
            [LocationEvents::BEFORE_HIDE_LOCATION, 10],
377
        ]);
378
        $this->assertSame($notCalledListeners, [
379
            [LocationEvents::HIDE_LOCATION, 0],
380
            [LocationEvents::BEFORE_HIDE_LOCATION, 0],
381
        ]);
382
    }
383
384
    public function testSwapLocationEvents()
385
    {
386
        $traceableEventDispatcher = $this->getEventDispatcher(
387
            LocationEvents::BEFORE_SWAP_LOCATION,
388
            LocationEvents::SWAP_LOCATION
389
        );
390
391
        $parameters = [
392
            $this->createMock(Location::class),
393
            $this->createMock(Location::class),
394
        ];
395
396
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
397
398
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
399
        $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...
400
401
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
402
403
        $this->assertSame($calledListeners, [
404
            [LocationEvents::BEFORE_SWAP_LOCATION, 0],
405
            [LocationEvents::SWAP_LOCATION, 0],
406
        ]);
407
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
408
    }
409
410 View Code Duplication
    public function testSwapLocationStopPropagationInBeforeEvents()
411
    {
412
        $traceableEventDispatcher = $this->getEventDispatcher(
413
            LocationEvents::BEFORE_SWAP_LOCATION,
414
            LocationEvents::SWAP_LOCATION
415
        );
416
417
        $parameters = [
418
            $this->createMock(Location::class),
419
            $this->createMock(Location::class),
420
        ];
421
422
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
423
424
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_SWAP_LOCATION, function (BeforeSwapLocationEvent $event) {
425
            $event->stopPropagation();
426
        }, 10);
427
428
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
429
        $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...
430
431
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
432
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
433
434
        $this->assertSame($calledListeners, [
435
            [LocationEvents::BEFORE_SWAP_LOCATION, 10],
436
        ]);
437
        $this->assertSame($notCalledListeners, [
438
            [LocationEvents::SWAP_LOCATION, 0],
439
            [LocationEvents::BEFORE_SWAP_LOCATION, 0],
440
        ]);
441
    }
442
443
    public function testMoveSubtreeEvents()
444
    {
445
        $traceableEventDispatcher = $this->getEventDispatcher(
446
            LocationEvents::BEFORE_MOVE_SUBTREE,
447
            LocationEvents::MOVE_SUBTREE
448
        );
449
450
        $parameters = [
451
            $this->createMock(Location::class),
452
            $this->createMock(Location::class),
453
        ];
454
455
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
456
457
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
458
        $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...
459
460
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
461
462
        $this->assertSame($calledListeners, [
463
            [LocationEvents::BEFORE_MOVE_SUBTREE, 0],
464
            [LocationEvents::MOVE_SUBTREE, 0],
465
        ]);
466
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
467
    }
468
469 View Code Duplication
    public function testMoveSubtreeStopPropagationInBeforeEvents()
470
    {
471
        $traceableEventDispatcher = $this->getEventDispatcher(
472
            LocationEvents::BEFORE_MOVE_SUBTREE,
473
            LocationEvents::MOVE_SUBTREE
474
        );
475
476
        $parameters = [
477
            $this->createMock(Location::class),
478
            $this->createMock(Location::class),
479
        ];
480
481
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
482
483
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_MOVE_SUBTREE, function (BeforeMoveSubtreeEvent $event) {
484
            $event->stopPropagation();
485
        }, 10);
486
487
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
488
        $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...
489
490
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
491
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
492
493
        $this->assertSame($calledListeners, [
494
            [LocationEvents::BEFORE_MOVE_SUBTREE, 10],
495
        ]);
496
        $this->assertSame($notCalledListeners, [
497
            [LocationEvents::MOVE_SUBTREE, 0],
498
            [LocationEvents::BEFORE_MOVE_SUBTREE, 0],
499
        ]);
500
    }
501
502 View Code Duplication
    public function testUpdateLocationEvents()
503
    {
504
        $traceableEventDispatcher = $this->getEventDispatcher(
505
            LocationEvents::BEFORE_UPDATE_LOCATION,
506
            LocationEvents::UPDATE_LOCATION
507
        );
508
509
        $parameters = [
510
            $this->createMock(Location::class),
511
            $this->createMock(LocationUpdateStruct::class),
512
        ];
513
514
        $updatedLocation = $this->createMock(Location::class);
515
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
516
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
517
518
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
519
        $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...
520
521
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
522
523
        $this->assertSame($updatedLocation, $result);
524
        $this->assertSame($calledListeners, [
525
            [LocationEvents::BEFORE_UPDATE_LOCATION, 0],
526
            [LocationEvents::UPDATE_LOCATION, 0],
527
        ]);
528
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
529
    }
530
531 View Code Duplication
    public function testReturnUpdateLocationResultInBeforeEvents()
532
    {
533
        $traceableEventDispatcher = $this->getEventDispatcher(
534
            LocationEvents::BEFORE_UPDATE_LOCATION,
535
            LocationEvents::UPDATE_LOCATION
536
        );
537
538
        $parameters = [
539
            $this->createMock(Location::class),
540
            $this->createMock(LocationUpdateStruct::class),
541
        ];
542
543
        $updatedLocation = $this->createMock(Location::class);
544
        $eventUpdatedLocation = $this->createMock(Location::class);
545
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
546
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
547
548
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_UPDATE_LOCATION, function (BeforeUpdateLocationEvent $event) use ($eventUpdatedLocation) {
549
            $event->setUpdatedLocation($eventUpdatedLocation);
550
        }, 10);
551
552
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
553
        $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...
554
555
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
556
557
        $this->assertSame($eventUpdatedLocation, $result);
558
        $this->assertSame($calledListeners, [
559
            [LocationEvents::BEFORE_UPDATE_LOCATION, 10],
560
            [LocationEvents::BEFORE_UPDATE_LOCATION, 0],
561
            [LocationEvents::UPDATE_LOCATION, 0],
562
        ]);
563
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
564
    }
565
566 View Code Duplication
    public function testUpdateLocationStopPropagationInBeforeEvents()
567
    {
568
        $traceableEventDispatcher = $this->getEventDispatcher(
569
            LocationEvents::BEFORE_UPDATE_LOCATION,
570
            LocationEvents::UPDATE_LOCATION
571
        );
572
573
        $parameters = [
574
            $this->createMock(Location::class),
575
            $this->createMock(LocationUpdateStruct::class),
576
        ];
577
578
        $updatedLocation = $this->createMock(Location::class);
579
        $eventUpdatedLocation = $this->createMock(Location::class);
580
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
581
        $innerServiceMock->method('updateLocation')->willReturn($updatedLocation);
582
583
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_UPDATE_LOCATION, function (BeforeUpdateLocationEvent $event) use ($eventUpdatedLocation) {
584
            $event->setUpdatedLocation($eventUpdatedLocation);
585
            $event->stopPropagation();
586
        }, 10);
587
588
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
589
        $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...
590
591
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
592
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
593
594
        $this->assertSame($eventUpdatedLocation, $result);
595
        $this->assertSame($calledListeners, [
596
            [LocationEvents::BEFORE_UPDATE_LOCATION, 10],
597
        ]);
598
        $this->assertSame($notCalledListeners, [
599
            [LocationEvents::UPDATE_LOCATION, 0],
600
            [LocationEvents::BEFORE_UPDATE_LOCATION, 0],
601
        ]);
602
    }
603
604 View Code Duplication
    public function testCreateLocationEvents()
605
    {
606
        $traceableEventDispatcher = $this->getEventDispatcher(
607
            LocationEvents::BEFORE_CREATE_LOCATION,
608
            LocationEvents::CREATE_LOCATION
609
        );
610
611
        $parameters = [
612
            $this->createMock(ContentInfo::class),
613
            $this->createMock(LocationCreateStruct::class),
614
        ];
615
616
        $location = $this->createMock(Location::class);
617
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
618
        $innerServiceMock->method('createLocation')->willReturn($location);
619
620
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
621
        $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...
622
623
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
624
625
        $this->assertSame($location, $result);
626
        $this->assertSame($calledListeners, [
627
            [LocationEvents::BEFORE_CREATE_LOCATION, 0],
628
            [LocationEvents::CREATE_LOCATION, 0],
629
        ]);
630
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
631
    }
632
633 View Code Duplication
    public function testReturnCreateLocationResultInBeforeEvents()
634
    {
635
        $traceableEventDispatcher = $this->getEventDispatcher(
636
            LocationEvents::BEFORE_CREATE_LOCATION,
637
            LocationEvents::CREATE_LOCATION
638
        );
639
640
        $parameters = [
641
            $this->createMock(ContentInfo::class),
642
            $this->createMock(LocationCreateStruct::class),
643
        ];
644
645
        $location = $this->createMock(Location::class);
646
        $eventLocation = $this->createMock(Location::class);
647
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
648
        $innerServiceMock->method('createLocation')->willReturn($location);
649
650
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_CREATE_LOCATION, function (BeforeCreateLocationEvent $event) use ($eventLocation) {
651
            $event->setLocation($eventLocation);
652
        }, 10);
653
654
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
655
        $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...
656
657
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
658
659
        $this->assertSame($eventLocation, $result);
660
        $this->assertSame($calledListeners, [
661
            [LocationEvents::BEFORE_CREATE_LOCATION, 10],
662
            [LocationEvents::BEFORE_CREATE_LOCATION, 0],
663
            [LocationEvents::CREATE_LOCATION, 0],
664
        ]);
665
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
666
    }
667
668 View Code Duplication
    public function testCreateLocationStopPropagationInBeforeEvents()
669
    {
670
        $traceableEventDispatcher = $this->getEventDispatcher(
671
            LocationEvents::BEFORE_CREATE_LOCATION,
672
            LocationEvents::CREATE_LOCATION
673
        );
674
675
        $parameters = [
676
            $this->createMock(ContentInfo::class),
677
            $this->createMock(LocationCreateStruct::class),
678
        ];
679
680
        $location = $this->createMock(Location::class);
681
        $eventLocation = $this->createMock(Location::class);
682
        $innerServiceMock = $this->createMock(LocationServiceInterface::class);
683
        $innerServiceMock->method('createLocation')->willReturn($location);
684
685
        $traceableEventDispatcher->addListener(LocationEvents::BEFORE_CREATE_LOCATION, function (BeforeCreateLocationEvent $event) use ($eventLocation) {
686
            $event->setLocation($eventLocation);
687
            $event->stopPropagation();
688
        }, 10);
689
690
        $service = new LocationService($innerServiceMock, $traceableEventDispatcher);
691
        $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...
692
693
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
694
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
695
696
        $this->assertSame($eventLocation, $result);
697
        $this->assertSame($calledListeners, [
698
            [LocationEvents::BEFORE_CREATE_LOCATION, 10],
699
        ]);
700
        $this->assertSame($notCalledListeners, [
701
            [LocationEvents::CREATE_LOCATION, 0],
702
            [LocationEvents::BEFORE_CREATE_LOCATION, 0],
703
        ]);
704
    }
705
}
706