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

ContentServiceTest::testRevealContentEvents()   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\ContentService as ContentServiceInterface;
10
use eZ\Publish\API\Repository\Events\Content\AddRelationEvent as AddRelationEventInterface;
11
use eZ\Publish\API\Repository\Events\Content\BeforeAddRelationEvent as BeforeAddRelationEventInterface;
12
use eZ\Publish\API\Repository\Events\Content\BeforeCopyContentEvent as BeforeCopyContentEventInterface;
13
use eZ\Publish\API\Repository\Events\Content\BeforeCreateContentDraftEvent as BeforeCreateContentDraftEventInterface;
14
use eZ\Publish\API\Repository\Events\Content\BeforeCreateContentEvent as BeforeCreateContentEventInterface;
15
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteContentEvent as BeforeDeleteContentEventInterface;
16
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteRelationEvent as BeforeDeleteRelationEventInterface;
17
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteTranslationEvent as BeforeDeleteTranslationEventInterface;
18
use eZ\Publish\API\Repository\Events\Content\BeforeDeleteVersionEvent as BeforeDeleteVersionEventInterface;
19
use eZ\Publish\API\Repository\Events\Content\BeforeHideContentEvent as BeforeHideContentEventInterface;
20
use eZ\Publish\API\Repository\Events\Content\BeforePublishVersionEvent as BeforePublishVersionEventInterface;
21
use eZ\Publish\API\Repository\Events\Content\BeforeRevealContentEvent as BeforeRevealContentEventInterface;
22
use eZ\Publish\API\Repository\Events\Content\BeforeUpdateContentEvent as BeforeUpdateContentEventInterface;
23
use eZ\Publish\API\Repository\Events\Content\BeforeUpdateContentMetadataEvent as BeforeUpdateContentMetadataEventInterface;
24
use eZ\Publish\API\Repository\Events\Content\CopyContentEvent as CopyContentEventInterface;
25
use eZ\Publish\API\Repository\Events\Content\CreateContentDraftEvent as CreateContentDraftEventInterface;
26
use eZ\Publish\API\Repository\Events\Content\CreateContentEvent as CreateContentEventInterface;
27
use eZ\Publish\API\Repository\Events\Content\DeleteContentEvent as DeleteContentEventInterface;
28
use eZ\Publish\API\Repository\Events\Content\DeleteRelationEvent as DeleteRelationEventInterface;
29
use eZ\Publish\API\Repository\Events\Content\DeleteTranslationEvent as DeleteTranslationEventInterface;
30
use eZ\Publish\API\Repository\Events\Content\DeleteVersionEvent as DeleteVersionEventInterface;
31
use eZ\Publish\API\Repository\Events\Content\HideContentEvent as HideContentEventInterface;
32
use eZ\Publish\API\Repository\Events\Content\PublishVersionEvent as PublishVersionEventInterface;
33
use eZ\Publish\API\Repository\Events\Content\RevealContentEvent as RevealContentEventInterface;
34
use eZ\Publish\API\Repository\Events\Content\UpdateContentEvent as UpdateContentEventInterface;
35
use eZ\Publish\API\Repository\Events\Content\UpdateContentMetadataEvent as UpdateContentMetadataEventInterface;
36
use eZ\Publish\API\Repository\Values\Content\Content;
37
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
38
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
39
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
40
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
41
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
42
use eZ\Publish\API\Repository\Values\Content\Relation;
43
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
44
use eZ\Publish\API\Repository\Values\User\User;
45
use eZ\Publish\Core\Event\ContentService;
46
47
class ContentServiceTest extends AbstractServiceTest
48
{
49 View Code Duplication
    public function testDeleteContentEvents()
50
    {
51
        $traceableEventDispatcher = $this->getEventDispatcher(
52
            BeforeDeleteContentEventInterface::class,
53
            DeleteContentEventInterface::class
54
        );
55
56
        $parameters = [
57
            $this->createMock(ContentInfo::class),
58
        ];
59
60
        $locations = [];
61
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
62
        $innerServiceMock->method('deleteContent')->willReturn($locations);
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...
63
64
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
65
        $result = $service->deleteContent(...$parameters);
66
67
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
68
69
        $this->assertSame($locations, $result);
70
        $this->assertSame($calledListeners, [
71
            [BeforeDeleteContentEventInterface::class, 0],
72
            [DeleteContentEventInterface::class, 0],
73
        ]);
74
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
75
    }
76
77
    public function testReturnDeleteContentResultInBeforeEvents()
78
    {
79
        $traceableEventDispatcher = $this->getEventDispatcher(
80
            BeforeDeleteContentEventInterface::class,
81
            DeleteContentEventInterface::class
82
        );
83
84
        $parameters = [
85
            $this->createMock(ContentInfo::class),
86
        ];
87
88
        $locations = [];
89
        $eventLocations = [];
90
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
91
        $innerServiceMock->method('deleteContent')->willReturn($locations);
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...
92
93
        $traceableEventDispatcher->addListener(BeforeDeleteContentEventInterface::class, function (BeforeDeleteContentEventInterface $event) use ($eventLocations) {
94
            $event->setLocations($eventLocations);
95
        }, 10);
96
97
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
98
        $result = $service->deleteContent(...$parameters);
99
100
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
101
102
        $this->assertSame($eventLocations, $result);
103
        $this->assertSame($calledListeners, [
104
            [BeforeDeleteContentEventInterface::class, 10],
105
            [BeforeDeleteContentEventInterface::class, 0],
106
            [DeleteContentEventInterface::class, 0],
107
        ]);
108
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
109
    }
110
111
    public function testDeleteContentStopPropagationInBeforeEvents()
112
    {
113
        $traceableEventDispatcher = $this->getEventDispatcher(
114
            BeforeDeleteContentEventInterface::class,
115
            DeleteContentEventInterface::class
116
        );
117
118
        $parameters = [
119
            $this->createMock(ContentInfo::class),
120
        ];
121
122
        $locations = [];
123
        $eventLocations = [];
124
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
125
        $innerServiceMock->method('deleteContent')->willReturn($locations);
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...
126
127
        $traceableEventDispatcher->addListener(BeforeDeleteContentEventInterface::class, function (BeforeDeleteContentEventInterface $event) use ($eventLocations) {
128
            $event->setLocations($eventLocations);
129
            $event->stopPropagation();
130
        }, 10);
131
132
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
133
        $result = $service->deleteContent(...$parameters);
134
135
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
136
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
137
138
        $this->assertSame($eventLocations, $result);
139
        $this->assertSame($calledListeners, [
140
            [BeforeDeleteContentEventInterface::class, 10],
141
        ]);
142
        $this->assertSame($notCalledListeners, [
143
            [BeforeDeleteContentEventInterface::class, 0],
144
            [DeleteContentEventInterface::class, 0],
145
        ]);
146
    }
147
148 View Code Duplication
    public function testCopyContentEvents()
149
    {
150
        $traceableEventDispatcher = $this->getEventDispatcher(
151
            BeforeCopyContentEventInterface::class,
152
            CopyContentEventInterface::class
153
        );
154
155
        $parameters = [
156
            $this->createMock(ContentInfo::class),
157
            $this->createMock(LocationCreateStruct::class),
158
            $this->createMock(VersionInfo::class),
159
        ];
160
161
        $content = $this->createMock(Content::class);
162
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
163
        $innerServiceMock->method('copyContent')->willReturn($content);
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...
164
165
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
166
        $result = $service->copyContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copyContent() misses a required argument $destinationLocationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
167
168
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
169
170
        $this->assertSame($content, $result);
171
        $this->assertSame($calledListeners, [
172
            [BeforeCopyContentEventInterface::class, 0],
173
            [CopyContentEventInterface::class, 0],
174
        ]);
175
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
176
    }
177
178
    public function testReturnCopyContentResultInBeforeEvents()
179
    {
180
        $traceableEventDispatcher = $this->getEventDispatcher(
181
            BeforeCopyContentEventInterface::class,
182
            CopyContentEventInterface::class
183
        );
184
185
        $parameters = [
186
            $this->createMock(ContentInfo::class),
187
            $this->createMock(LocationCreateStruct::class),
188
            $this->createMock(VersionInfo::class),
189
        ];
190
191
        $content = $this->createMock(Content::class);
192
        $eventContent = $this->createMock(Content::class);
193
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
194
        $innerServiceMock->method('copyContent')->willReturn($content);
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...
195
196
        $traceableEventDispatcher->addListener(BeforeCopyContentEventInterface::class, function (BeforeCopyContentEventInterface $event) use ($eventContent) {
197
            $event->setContent($eventContent);
198
        }, 10);
199
200
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
201
        $result = $service->copyContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copyContent() misses a required argument $destinationLocationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
202
203
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
204
205
        $this->assertSame($eventContent, $result);
206
        $this->assertSame($calledListeners, [
207
            [BeforeCopyContentEventInterface::class, 10],
208
            [BeforeCopyContentEventInterface::class, 0],
209
            [CopyContentEventInterface::class, 0],
210
        ]);
211
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
212
    }
213
214
    public function testCopyContentStopPropagationInBeforeEvents()
215
    {
216
        $traceableEventDispatcher = $this->getEventDispatcher(
217
            BeforeCopyContentEventInterface::class,
218
            CopyContentEventInterface::class
219
        );
220
221
        $parameters = [
222
            $this->createMock(ContentInfo::class),
223
            $this->createMock(LocationCreateStruct::class),
224
            $this->createMock(VersionInfo::class),
225
        ];
226
227
        $content = $this->createMock(Content::class);
228
        $eventContent = $this->createMock(Content::class);
229
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
230
        $innerServiceMock->method('copyContent')->willReturn($content);
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...
231
232
        $traceableEventDispatcher->addListener(BeforeCopyContentEventInterface::class, function (BeforeCopyContentEventInterface $event) use ($eventContent) {
233
            $event->setContent($eventContent);
234
            $event->stopPropagation();
235
        }, 10);
236
237
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
238
        $result = $service->copyContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to copyContent() misses a required argument $destinationLocationCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
239
240
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
241
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
242
243
        $this->assertSame($eventContent, $result);
244
        $this->assertSame($calledListeners, [
245
            [BeforeCopyContentEventInterface::class, 10],
246
        ]);
247
        $this->assertSame($notCalledListeners, [
248
            [BeforeCopyContentEventInterface::class, 0],
249
            [CopyContentEventInterface::class, 0],
250
        ]);
251
    }
252
253 View Code Duplication
    public function testUpdateContentEvents()
254
    {
255
        $traceableEventDispatcher = $this->getEventDispatcher(
256
            BeforeUpdateContentEventInterface::class,
257
            UpdateContentEventInterface::class
258
        );
259
260
        $parameters = [
261
            $this->createMock(VersionInfo::class),
262
            $this->createMock(ContentUpdateStruct::class),
263
        ];
264
265
        $content = $this->createMock(Content::class);
266
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
267
        $innerServiceMock->method('updateContent')->willReturn($content);
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...
268
269
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
270
        $result = $service->updateContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContent() misses a required argument $contentUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
271
272
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
273
274
        $this->assertSame($content, $result);
275
        $this->assertSame($calledListeners, [
276
            [BeforeUpdateContentEventInterface::class, 0],
277
            [UpdateContentEventInterface::class, 0],
278
        ]);
279
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
280
    }
281
282 View Code Duplication
    public function testReturnUpdateContentResultInBeforeEvents()
283
    {
284
        $traceableEventDispatcher = $this->getEventDispatcher(
285
            BeforeUpdateContentEventInterface::class,
286
            UpdateContentEventInterface::class
287
        );
288
289
        $parameters = [
290
            $this->createMock(VersionInfo::class),
291
            $this->createMock(ContentUpdateStruct::class),
292
        ];
293
294
        $content = $this->createMock(Content::class);
295
        $eventContent = $this->createMock(Content::class);
296
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
297
        $innerServiceMock->method('updateContent')->willReturn($content);
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...
298
299
        $traceableEventDispatcher->addListener(BeforeUpdateContentEventInterface::class, function (BeforeUpdateContentEventInterface $event) use ($eventContent) {
300
            $event->setContent($eventContent);
301
        }, 10);
302
303
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
304
        $result = $service->updateContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContent() misses a required argument $contentUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
305
306
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
307
308
        $this->assertSame($eventContent, $result);
309
        $this->assertSame($calledListeners, [
310
            [BeforeUpdateContentEventInterface::class, 10],
311
            [BeforeUpdateContentEventInterface::class, 0],
312
            [UpdateContentEventInterface::class, 0],
313
        ]);
314
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
315
    }
316
317 View Code Duplication
    public function testUpdateContentStopPropagationInBeforeEvents()
318
    {
319
        $traceableEventDispatcher = $this->getEventDispatcher(
320
            BeforeUpdateContentEventInterface::class,
321
            UpdateContentEventInterface::class
322
        );
323
324
        $parameters = [
325
            $this->createMock(VersionInfo::class),
326
            $this->createMock(ContentUpdateStruct::class),
327
        ];
328
329
        $content = $this->createMock(Content::class);
330
        $eventContent = $this->createMock(Content::class);
331
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
332
        $innerServiceMock->method('updateContent')->willReturn($content);
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...
333
334
        $traceableEventDispatcher->addListener(BeforeUpdateContentEventInterface::class, function (BeforeUpdateContentEventInterface $event) use ($eventContent) {
335
            $event->setContent($eventContent);
336
            $event->stopPropagation();
337
        }, 10);
338
339
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
340
        $result = $service->updateContent(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContent() misses a required argument $contentUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
341
342
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
343
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
344
345
        $this->assertSame($eventContent, $result);
346
        $this->assertSame($calledListeners, [
347
            [BeforeUpdateContentEventInterface::class, 10],
348
        ]);
349
        $this->assertSame($notCalledListeners, [
350
            [BeforeUpdateContentEventInterface::class, 0],
351
            [UpdateContentEventInterface::class, 0],
352
        ]);
353
    }
354
355
    public function testDeleteRelationEvents()
356
    {
357
        $traceableEventDispatcher = $this->getEventDispatcher(
358
            BeforeDeleteRelationEventInterface::class,
359
            DeleteRelationEventInterface::class
360
        );
361
362
        $parameters = [
363
            $this->createMock(VersionInfo::class),
364
            $this->createMock(ContentInfo::class),
365
        ];
366
367
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
368
369
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
370
        $service->deleteRelation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to deleteRelation() misses a required argument $destinationContent.

This check looks for function calls that miss required arguments.

Loading history...
371
372
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
373
374
        $this->assertSame($calledListeners, [
375
            [BeforeDeleteRelationEventInterface::class, 0],
376
            [DeleteRelationEventInterface::class, 0],
377
        ]);
378
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
379
    }
380
381 View Code Duplication
    public function testDeleteRelationStopPropagationInBeforeEvents()
382
    {
383
        $traceableEventDispatcher = $this->getEventDispatcher(
384
            BeforeDeleteRelationEventInterface::class,
385
            DeleteRelationEventInterface::class
386
        );
387
388
        $parameters = [
389
            $this->createMock(VersionInfo::class),
390
            $this->createMock(ContentInfo::class),
391
        ];
392
393
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
394
395
        $traceableEventDispatcher->addListener(BeforeDeleteRelationEventInterface::class, function (BeforeDeleteRelationEventInterface $event) {
396
            $event->stopPropagation();
397
        }, 10);
398
399
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
400
        $service->deleteRelation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to deleteRelation() misses a required argument $destinationContent.

This check looks for function calls that miss required arguments.

Loading history...
401
402
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
403
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
404
405
        $this->assertSame($calledListeners, [
406
            [BeforeDeleteRelationEventInterface::class, 10],
407
        ]);
408
        $this->assertSame($notCalledListeners, [
409
            [BeforeDeleteRelationEventInterface::class, 0],
410
            [DeleteRelationEventInterface::class, 0],
411
        ]);
412
    }
413
414 View Code Duplication
    public function testCreateContentEvents()
415
    {
416
        $traceableEventDispatcher = $this->getEventDispatcher(
417
            BeforeCreateContentEventInterface::class,
418
            CreateContentEventInterface::class
419
        );
420
421
        $parameters = [
422
            $this->createMock(ContentCreateStruct::class),
423
            [],
424
        ];
425
426
        $content = $this->createMock(Content::class);
427
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
428
        $innerServiceMock->method('createContent')->willReturn($content);
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...
429
430
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
431
        $result = $service->createContent(...$parameters);
432
433
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
434
435
        $this->assertSame($content, $result);
436
        $this->assertSame($calledListeners, [
437
            [BeforeCreateContentEventInterface::class, 0],
438
            [CreateContentEventInterface::class, 0],
439
        ]);
440
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
441
    }
442
443 View Code Duplication
    public function testReturnCreateContentResultInBeforeEvents()
444
    {
445
        $traceableEventDispatcher = $this->getEventDispatcher(
446
            BeforeCreateContentEventInterface::class,
447
            CreateContentEventInterface::class
448
        );
449
450
        $parameters = [
451
            $this->createMock(ContentCreateStruct::class),
452
            [],
453
        ];
454
455
        $content = $this->createMock(Content::class);
456
        $eventContent = $this->createMock(Content::class);
457
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
458
        $innerServiceMock->method('createContent')->willReturn($content);
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...
459
460
        $traceableEventDispatcher->addListener(BeforeCreateContentEventInterface::class, function (BeforeCreateContentEventInterface $event) use ($eventContent) {
461
            $event->setContent($eventContent);
462
        }, 10);
463
464
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
465
        $result = $service->createContent(...$parameters);
466
467
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
468
469
        $this->assertSame($eventContent, $result);
470
        $this->assertSame($calledListeners, [
471
            [BeforeCreateContentEventInterface::class, 10],
472
            [BeforeCreateContentEventInterface::class, 0],
473
            [CreateContentEventInterface::class, 0],
474
        ]);
475
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
476
    }
477
478 View Code Duplication
    public function testCreateContentStopPropagationInBeforeEvents()
479
    {
480
        $traceableEventDispatcher = $this->getEventDispatcher(
481
            BeforeCreateContentEventInterface::class,
482
            CreateContentEventInterface::class
483
        );
484
485
        $parameters = [
486
            $this->createMock(ContentCreateStruct::class),
487
            [],
488
        ];
489
490
        $content = $this->createMock(Content::class);
491
        $eventContent = $this->createMock(Content::class);
492
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
493
        $innerServiceMock->method('createContent')->willReturn($content);
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...
494
495
        $traceableEventDispatcher->addListener(BeforeCreateContentEventInterface::class, function (BeforeCreateContentEventInterface $event) use ($eventContent) {
496
            $event->setContent($eventContent);
497
            $event->stopPropagation();
498
        }, 10);
499
500
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
501
        $result = $service->createContent(...$parameters);
502
503
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
504
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
505
506
        $this->assertSame($eventContent, $result);
507
        $this->assertSame($calledListeners, [
508
            [BeforeCreateContentEventInterface::class, 10],
509
        ]);
510
        $this->assertSame($notCalledListeners, [
511
            [BeforeCreateContentEventInterface::class, 0],
512
            [CreateContentEventInterface::class, 0],
513
        ]);
514
    }
515
516
    public function testHideContentEvents()
517
    {
518
        $traceableEventDispatcher = $this->getEventDispatcher(
519
            BeforeHideContentEventInterface::class,
520
            HideContentEventInterface::class
521
        );
522
523
        $parameters = [
524
            $this->createMock(ContentInfo::class),
525
        ];
526
527
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
528
529
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
530
        $service->hideContent(...$parameters);
531
532
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
533
534
        $this->assertSame($calledListeners, [
535
            [BeforeHideContentEventInterface::class, 0],
536
            [HideContentEventInterface::class, 0],
537
        ]);
538
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
539
    }
540
541
    public function testHideContentStopPropagationInBeforeEvents()
542
    {
543
        $traceableEventDispatcher = $this->getEventDispatcher(
544
            BeforeHideContentEventInterface::class,
545
            HideContentEventInterface::class
546
        );
547
548
        $parameters = [
549
            $this->createMock(ContentInfo::class),
550
        ];
551
552
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
553
554
        $traceableEventDispatcher->addListener(BeforeHideContentEventInterface::class, function (BeforeHideContentEventInterface $event) {
555
            $event->stopPropagation();
556
        }, 10);
557
558
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
559
        $service->hideContent(...$parameters);
560
561
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
562
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
563
564
        $this->assertSame($calledListeners, [
565
            [BeforeHideContentEventInterface::class, 10],
566
        ]);
567
        $this->assertSame($notCalledListeners, [
568
            [BeforeHideContentEventInterface::class, 0],
569
            [HideContentEventInterface::class, 0],
570
        ]);
571
    }
572
573
    public function testDeleteVersionEvents()
574
    {
575
        $traceableEventDispatcher = $this->getEventDispatcher(
576
            BeforeDeleteVersionEventInterface::class,
577
            DeleteVersionEventInterface::class
578
        );
579
580
        $parameters = [
581
            $this->createMock(VersionInfo::class),
582
        ];
583
584
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
585
586
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
587
        $service->deleteVersion(...$parameters);
588
589
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
590
591
        $this->assertSame($calledListeners, [
592
            [BeforeDeleteVersionEventInterface::class, 0],
593
            [DeleteVersionEventInterface::class, 0],
594
        ]);
595
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
596
    }
597
598
    public function testDeleteVersionStopPropagationInBeforeEvents()
599
    {
600
        $traceableEventDispatcher = $this->getEventDispatcher(
601
            BeforeDeleteVersionEventInterface::class,
602
            DeleteVersionEventInterface::class
603
        );
604
605
        $parameters = [
606
            $this->createMock(VersionInfo::class),
607
        ];
608
609
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
610
611
        $traceableEventDispatcher->addListener(BeforeDeleteVersionEventInterface::class, function (BeforeDeleteVersionEventInterface $event) {
612
            $event->stopPropagation();
613
        }, 10);
614
615
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
616
        $service->deleteVersion(...$parameters);
617
618
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
619
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
620
621
        $this->assertSame($calledListeners, [
622
            [BeforeDeleteVersionEventInterface::class, 10],
623
        ]);
624
        $this->assertSame($notCalledListeners, [
625
            [BeforeDeleteVersionEventInterface::class, 0],
626
            [DeleteVersionEventInterface::class, 0],
627
        ]);
628
    }
629
630 View Code Duplication
    public function testAddRelationEvents()
631
    {
632
        $traceableEventDispatcher = $this->getEventDispatcher(
633
            BeforeAddRelationEventInterface::class,
634
            AddRelationEventInterface::class
635
        );
636
637
        $parameters = [
638
            $this->createMock(VersionInfo::class),
639
            $this->createMock(ContentInfo::class),
640
        ];
641
642
        $relation = $this->createMock(Relation::class);
643
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
644
        $innerServiceMock->method('addRelation')->willReturn($relation);
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...
645
646
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
647
        $result = $service->addRelation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addRelation() misses a required argument $destinationContent.

This check looks for function calls that miss required arguments.

Loading history...
648
649
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
650
651
        $this->assertSame($relation, $result);
652
        $this->assertSame($calledListeners, [
653
            [BeforeAddRelationEventInterface::class, 0],
654
            [AddRelationEventInterface::class, 0],
655
        ]);
656
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
657
    }
658
659 View Code Duplication
    public function testReturnAddRelationResultInBeforeEvents()
660
    {
661
        $traceableEventDispatcher = $this->getEventDispatcher(
662
            BeforeAddRelationEventInterface::class,
663
            AddRelationEventInterface::class
664
        );
665
666
        $parameters = [
667
            $this->createMock(VersionInfo::class),
668
            $this->createMock(ContentInfo::class),
669
        ];
670
671
        $relation = $this->createMock(Relation::class);
672
        $eventRelation = $this->createMock(Relation::class);
673
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
674
        $innerServiceMock->method('addRelation')->willReturn($relation);
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...
675
676
        $traceableEventDispatcher->addListener(BeforeAddRelationEventInterface::class, function (BeforeAddRelationEventInterface $event) use ($eventRelation) {
677
            $event->setRelation($eventRelation);
678
        }, 10);
679
680
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
681
        $result = $service->addRelation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addRelation() misses a required argument $destinationContent.

This check looks for function calls that miss required arguments.

Loading history...
682
683
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
684
685
        $this->assertSame($eventRelation, $result);
686
        $this->assertSame($calledListeners, [
687
            [BeforeAddRelationEventInterface::class, 10],
688
            [BeforeAddRelationEventInterface::class, 0],
689
            [AddRelationEventInterface::class, 0],
690
        ]);
691
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
692
    }
693
694 View Code Duplication
    public function testAddRelationStopPropagationInBeforeEvents()
695
    {
696
        $traceableEventDispatcher = $this->getEventDispatcher(
697
            BeforeAddRelationEventInterface::class,
698
            AddRelationEventInterface::class
699
        );
700
701
        $parameters = [
702
            $this->createMock(VersionInfo::class),
703
            $this->createMock(ContentInfo::class),
704
        ];
705
706
        $relation = $this->createMock(Relation::class);
707
        $eventRelation = $this->createMock(Relation::class);
708
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
709
        $innerServiceMock->method('addRelation')->willReturn($relation);
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...
710
711
        $traceableEventDispatcher->addListener(BeforeAddRelationEventInterface::class, function (BeforeAddRelationEventInterface $event) use ($eventRelation) {
712
            $event->setRelation($eventRelation);
713
            $event->stopPropagation();
714
        }, 10);
715
716
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
717
        $result = $service->addRelation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to addRelation() misses a required argument $destinationContent.

This check looks for function calls that miss required arguments.

Loading history...
718
719
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
720
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
721
722
        $this->assertSame($eventRelation, $result);
723
        $this->assertSame($calledListeners, [
724
            [BeforeAddRelationEventInterface::class, 10],
725
        ]);
726
        $this->assertSame($notCalledListeners, [
727
            [AddRelationEventInterface::class, 0],
728
            [BeforeAddRelationEventInterface::class, 0],
729
        ]);
730
    }
731
732 View Code Duplication
    public function testUpdateContentMetadataEvents()
733
    {
734
        $traceableEventDispatcher = $this->getEventDispatcher(
735
            BeforeUpdateContentMetadataEventInterface::class,
736
            UpdateContentMetadataEventInterface::class
737
        );
738
739
        $parameters = [
740
            $this->createMock(ContentInfo::class),
741
            $this->createMock(ContentMetadataUpdateStruct::class),
742
        ];
743
744
        $content = $this->createMock(Content::class);
745
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
746
        $innerServiceMock->method('updateContentMetadata')->willReturn($content);
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...
747
748
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
749
        $result = $service->updateContentMetadata(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContentMetadata() misses a required argument $contentMetadataUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
750
751
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
752
753
        $this->assertSame($content, $result);
754
        $this->assertSame($calledListeners, [
755
            [BeforeUpdateContentMetadataEventInterface::class, 0],
756
            [UpdateContentMetadataEventInterface::class, 0],
757
        ]);
758
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
759
    }
760
761 View Code Duplication
    public function testReturnUpdateContentMetadataResultInBeforeEvents()
762
    {
763
        $traceableEventDispatcher = $this->getEventDispatcher(
764
            BeforeUpdateContentMetadataEventInterface::class,
765
            UpdateContentMetadataEventInterface::class
766
        );
767
768
        $parameters = [
769
            $this->createMock(ContentInfo::class),
770
            $this->createMock(ContentMetadataUpdateStruct::class),
771
        ];
772
773
        $content = $this->createMock(Content::class);
774
        $eventContent = $this->createMock(Content::class);
775
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
776
        $innerServiceMock->method('updateContentMetadata')->willReturn($content);
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...
777
778
        $traceableEventDispatcher->addListener(BeforeUpdateContentMetadataEventInterface::class, function (BeforeUpdateContentMetadataEventInterface $event) use ($eventContent) {
779
            $event->setContent($eventContent);
780
        }, 10);
781
782
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
783
        $result = $service->updateContentMetadata(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContentMetadata() misses a required argument $contentMetadataUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
784
785
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
786
787
        $this->assertSame($eventContent, $result);
788
        $this->assertSame($calledListeners, [
789
            [BeforeUpdateContentMetadataEventInterface::class, 10],
790
            [BeforeUpdateContentMetadataEventInterface::class, 0],
791
            [UpdateContentMetadataEventInterface::class, 0],
792
        ]);
793
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
794
    }
795
796 View Code Duplication
    public function testUpdateContentMetadataStopPropagationInBeforeEvents()
797
    {
798
        $traceableEventDispatcher = $this->getEventDispatcher(
799
            BeforeUpdateContentMetadataEventInterface::class,
800
            UpdateContentMetadataEventInterface::class
801
        );
802
803
        $parameters = [
804
            $this->createMock(ContentInfo::class),
805
            $this->createMock(ContentMetadataUpdateStruct::class),
806
        ];
807
808
        $content = $this->createMock(Content::class);
809
        $eventContent = $this->createMock(Content::class);
810
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
811
        $innerServiceMock->method('updateContentMetadata')->willReturn($content);
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...
812
813
        $traceableEventDispatcher->addListener(BeforeUpdateContentMetadataEventInterface::class, function (BeforeUpdateContentMetadataEventInterface $event) use ($eventContent) {
814
            $event->setContent($eventContent);
815
            $event->stopPropagation();
816
        }, 10);
817
818
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
819
        $result = $service->updateContentMetadata(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateContentMetadata() misses a required argument $contentMetadataUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
820
821
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
822
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
823
824
        $this->assertSame($eventContent, $result);
825
        $this->assertSame($calledListeners, [
826
            [BeforeUpdateContentMetadataEventInterface::class, 10],
827
        ]);
828
        $this->assertSame($notCalledListeners, [
829
            [BeforeUpdateContentMetadataEventInterface::class, 0],
830
            [UpdateContentMetadataEventInterface::class, 0],
831
        ]);
832
    }
833
834
    public function testDeleteTranslationEvents()
835
    {
836
        $traceableEventDispatcher = $this->getEventDispatcher(
837
            BeforeDeleteTranslationEventInterface::class,
838
            DeleteTranslationEventInterface::class
839
        );
840
841
        $parameters = [
842
            $this->createMock(ContentInfo::class),
843
            'random_value_5cff79c31a2f31.74205767',
844
        ];
845
846
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
847
848
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
849
        $service->deleteTranslation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to deleteTranslation() misses a required argument $languageCode.

This check looks for function calls that miss required arguments.

Loading history...
850
851
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
852
853
        $this->assertSame($calledListeners, [
854
            [BeforeDeleteTranslationEventInterface::class, 0],
855
            [DeleteTranslationEventInterface::class, 0],
856
        ]);
857
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
858
    }
859
860
    public function testDeleteTranslationStopPropagationInBeforeEvents()
861
    {
862
        $traceableEventDispatcher = $this->getEventDispatcher(
863
            BeforeDeleteTranslationEventInterface::class,
864
            DeleteTranslationEventInterface::class
865
        );
866
867
        $parameters = [
868
            $this->createMock(ContentInfo::class),
869
            'random_value_5cff79c31a2fc0.71971617',
870
        ];
871
872
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
873
874
        $traceableEventDispatcher->addListener(BeforeDeleteTranslationEventInterface::class, function (BeforeDeleteTranslationEventInterface $event) {
875
            $event->stopPropagation();
876
        }, 10);
877
878
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
879
        $service->deleteTranslation(...$parameters);
0 ignored issues
show
Bug introduced by
The call to deleteTranslation() misses a required argument $languageCode.

This check looks for function calls that miss required arguments.

Loading history...
880
881
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
882
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
883
884
        $this->assertSame($calledListeners, [
885
            [BeforeDeleteTranslationEventInterface::class, 10],
886
        ]);
887
        $this->assertSame($notCalledListeners, [
888
            [BeforeDeleteTranslationEventInterface::class, 0],
889
            [DeleteTranslationEventInterface::class, 0],
890
        ]);
891
    }
892
893 View Code Duplication
    public function testPublishVersionEvents()
894
    {
895
        $traceableEventDispatcher = $this->getEventDispatcher(
896
            BeforePublishVersionEventInterface::class,
897
            PublishVersionEventInterface::class
898
        );
899
900
        $parameters = [
901
            $this->createMock(VersionInfo::class),
902
            [],
903
        ];
904
905
        $content = $this->createMock(Content::class);
906
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
907
        $innerServiceMock->method('publishVersion')->willReturn($content);
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...
908
909
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
910
        $result = $service->publishVersion(...$parameters);
911
912
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
913
914
        $this->assertSame($content, $result);
915
        $this->assertSame($calledListeners, [
916
            [BeforePublishVersionEventInterface::class, 0],
917
            [PublishVersionEventInterface::class, 0],
918
        ]);
919
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
920
    }
921
922 View Code Duplication
    public function testReturnPublishVersionResultInBeforeEvents()
923
    {
924
        $traceableEventDispatcher = $this->getEventDispatcher(
925
            BeforePublishVersionEventInterface::class,
926
            PublishVersionEventInterface::class
927
        );
928
929
        $parameters = [
930
            $this->createMock(VersionInfo::class),
931
            [],
932
        ];
933
934
        $content = $this->createMock(Content::class);
935
        $eventContent = $this->createMock(Content::class);
936
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
937
        $innerServiceMock->method('publishVersion')->willReturn($content);
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...
938
939
        $traceableEventDispatcher->addListener(BeforePublishVersionEventInterface::class, function (BeforePublishVersionEventInterface $event) use ($eventContent) {
940
            $event->setContent($eventContent);
941
        }, 10);
942
943
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
944
        $result = $service->publishVersion(...$parameters);
945
946
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
947
948
        $this->assertSame($eventContent, $result);
949
        $this->assertSame($calledListeners, [
950
            [BeforePublishVersionEventInterface::class, 10],
951
            [BeforePublishVersionEventInterface::class, 0],
952
            [PublishVersionEventInterface::class, 0],
953
        ]);
954
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
955
    }
956
957 View Code Duplication
    public function testPublishVersionStopPropagationInBeforeEvents()
958
    {
959
        $traceableEventDispatcher = $this->getEventDispatcher(
960
            BeforePublishVersionEventInterface::class,
961
            PublishVersionEventInterface::class
962
        );
963
964
        $parameters = [
965
            $this->createMock(VersionInfo::class),
966
            [],
967
        ];
968
969
        $content = $this->createMock(Content::class);
970
        $eventContent = $this->createMock(Content::class);
971
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
972
        $innerServiceMock->method('publishVersion')->willReturn($content);
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...
973
974
        $traceableEventDispatcher->addListener(BeforePublishVersionEventInterface::class, function (BeforePublishVersionEventInterface $event) use ($eventContent) {
975
            $event->setContent($eventContent);
976
            $event->stopPropagation();
977
        }, 10);
978
979
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
980
        $result = $service->publishVersion(...$parameters);
981
982
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
983
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
984
985
        $this->assertSame($eventContent, $result);
986
        $this->assertSame($calledListeners, [
987
            [BeforePublishVersionEventInterface::class, 10],
988
        ]);
989
        $this->assertSame($notCalledListeners, [
990
            [BeforePublishVersionEventInterface::class, 0],
991
            [PublishVersionEventInterface::class, 0],
992
        ]);
993
    }
994
995 View Code Duplication
    public function testCreateContentDraftEvents()
996
    {
997
        $traceableEventDispatcher = $this->getEventDispatcher(
998
            BeforeCreateContentDraftEventInterface::class,
999
            CreateContentDraftEventInterface::class
1000
        );
1001
1002
        $parameters = [
1003
            $this->createMock(ContentInfo::class),
1004
            $this->createMock(VersionInfo::class),
1005
            $this->createMock(User::class),
1006
        ];
1007
1008
        $contentDraft = $this->createMock(Content::class);
1009
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
1010
        $innerServiceMock->method('createContentDraft')->willReturn($contentDraft);
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...
1011
1012
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
1013
        $result = $service->createContentDraft(...$parameters);
1014
1015
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1016
1017
        $this->assertSame($contentDraft, $result);
1018
        $this->assertSame($calledListeners, [
1019
            [BeforeCreateContentDraftEventInterface::class, 0],
1020
            [CreateContentDraftEventInterface::class, 0],
1021
        ]);
1022
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1023
    }
1024
1025
    public function testReturnCreateContentDraftResultInBeforeEvents()
1026
    {
1027
        $traceableEventDispatcher = $this->getEventDispatcher(
1028
            BeforeCreateContentDraftEventInterface::class,
1029
            CreateContentDraftEventInterface::class
1030
        );
1031
1032
        $parameters = [
1033
            $this->createMock(ContentInfo::class),
1034
            $this->createMock(VersionInfo::class),
1035
            $this->createMock(User::class),
1036
        ];
1037
1038
        $contentDraft = $this->createMock(Content::class);
1039
        $eventContentDraft = $this->createMock(Content::class);
1040
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
1041
        $innerServiceMock->method('createContentDraft')->willReturn($contentDraft);
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...
1042
1043
        $traceableEventDispatcher->addListener(BeforeCreateContentDraftEventInterface::class, function (BeforeCreateContentDraftEventInterface $event) use ($eventContentDraft) {
1044
            $event->setContentDraft($eventContentDraft);
1045
        }, 10);
1046
1047
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
1048
        $result = $service->createContentDraft(...$parameters);
1049
1050
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1051
1052
        $this->assertSame($eventContentDraft, $result);
1053
        $this->assertSame($calledListeners, [
1054
            [BeforeCreateContentDraftEventInterface::class, 10],
1055
            [BeforeCreateContentDraftEventInterface::class, 0],
1056
            [CreateContentDraftEventInterface::class, 0],
1057
        ]);
1058
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1059
    }
1060
1061
    public function testCreateContentDraftStopPropagationInBeforeEvents()
1062
    {
1063
        $traceableEventDispatcher = $this->getEventDispatcher(
1064
            BeforeCreateContentDraftEventInterface::class,
1065
            CreateContentDraftEventInterface::class
1066
        );
1067
1068
        $parameters = [
1069
            $this->createMock(ContentInfo::class),
1070
            $this->createMock(VersionInfo::class),
1071
            $this->createMock(User::class),
1072
        ];
1073
1074
        $contentDraft = $this->createMock(Content::class);
1075
        $eventContentDraft = $this->createMock(Content::class);
1076
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
1077
        $innerServiceMock->method('createContentDraft')->willReturn($contentDraft);
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...
1078
1079
        $traceableEventDispatcher->addListener(BeforeCreateContentDraftEventInterface::class, function (BeforeCreateContentDraftEventInterface $event) use ($eventContentDraft) {
1080
            $event->setContentDraft($eventContentDraft);
1081
            $event->stopPropagation();
1082
        }, 10);
1083
1084
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
1085
        $result = $service->createContentDraft(...$parameters);
1086
1087
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1088
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1089
1090
        $this->assertSame($eventContentDraft, $result);
1091
        $this->assertSame($calledListeners, [
1092
            [BeforeCreateContentDraftEventInterface::class, 10],
1093
        ]);
1094
        $this->assertSame($notCalledListeners, [
1095
            [BeforeCreateContentDraftEventInterface::class, 0],
1096
            [CreateContentDraftEventInterface::class, 0],
1097
        ]);
1098
    }
1099
1100
    public function testRevealContentEvents()
1101
    {
1102
        $traceableEventDispatcher = $this->getEventDispatcher(
1103
            BeforeRevealContentEventInterface::class,
1104
            RevealContentEventInterface::class
1105
        );
1106
1107
        $parameters = [
1108
            $this->createMock(ContentInfo::class),
1109
        ];
1110
1111
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
1112
1113
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
1114
        $service->revealContent(...$parameters);
1115
1116
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1117
1118
        $this->assertSame($calledListeners, [
1119
            [BeforeRevealContentEventInterface::class, 0],
1120
            [RevealContentEventInterface::class, 0],
1121
        ]);
1122
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
1123
    }
1124
1125
    public function testRevealContentStopPropagationInBeforeEvents()
1126
    {
1127
        $traceableEventDispatcher = $this->getEventDispatcher(
1128
            BeforeRevealContentEventInterface::class,
1129
            RevealContentEventInterface::class
1130
        );
1131
1132
        $parameters = [
1133
            $this->createMock(ContentInfo::class),
1134
        ];
1135
1136
        $innerServiceMock = $this->createMock(ContentServiceInterface::class);
1137
1138
        $traceableEventDispatcher->addListener(BeforeRevealContentEventInterface::class, function (BeforeRevealContentEventInterface $event) {
1139
            $event->stopPropagation();
1140
        }, 10);
1141
1142
        $service = new ContentService($innerServiceMock, $traceableEventDispatcher);
1143
        $service->revealContent(...$parameters);
1144
1145
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
1146
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
1147
1148
        $this->assertSame($calledListeners, [
1149
            [BeforeRevealContentEventInterface::class, 10],
1150
        ]);
1151
        $this->assertSame($notCalledListeners, [
1152
            [BeforeRevealContentEventInterface::class, 0],
1153
            [RevealContentEventInterface::class, 0],
1154
        ]);
1155
    }
1156
}
1157