Completed
Push — ezp-30616-follow-up ( de1597...f1c1e1 )
by
unknown
14:34
created

testDeleteSectionStopPropagationInBeforeEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\API\Repository\Events\Tests;
8
9
use eZ\Publish\API\Repository\Events\Section\AssignSectionEvent as AssignSectionEventInterface;
10
use eZ\Publish\API\Repository\Events\Section\AssignSectionToSubtreeEvent as AssignSectionToSubtreeEventInterface;
11
use eZ\Publish\API\Repository\Events\Section\BeforeAssignSectionEvent as BeforeAssignSectionEventInterface;
12
use eZ\Publish\API\Repository\Events\Section\BeforeAssignSectionToSubtreeEvent as BeforeAssignSectionToSubtreeEventInterface;
13
use eZ\Publish\API\Repository\Events\Section\BeforeCreateSectionEvent as BeforeCreateSectionEventInterface;
14
use eZ\Publish\API\Repository\Events\Section\BeforeDeleteSectionEvent as BeforeDeleteSectionEventInterface;
15
use eZ\Publish\API\Repository\Events\Section\BeforeUpdateSectionEvent as BeforeUpdateSectionEventInterface;
16
use eZ\Publish\API\Repository\Events\Section\CreateSectionEvent as CreateSectionEventInterface;
17
use eZ\Publish\API\Repository\Events\Section\DeleteSectionEvent as DeleteSectionEventInterface;
18
use eZ\Publish\API\Repository\Events\Section\UpdateSectionEvent as UpdateSectionEventInterface;
19
use eZ\Publish\API\Repository\SectionService as SectionServiceInterface;
20
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
21
use eZ\Publish\API\Repository\Values\Content\Location;
22
use eZ\Publish\API\Repository\Values\Content\Section;
23
use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct;
24
use eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct;
25
use eZ\Publish\API\Repository\Events\SectionService;
26
27
class SectionServiceTest extends AbstractServiceTest
28
{
29
    public function testAssignSectionEvents()
30
    {
31
        $traceableEventDispatcher = $this->getEventDispatcher(
32
            BeforeAssignSectionEventInterface::class,
33
            AssignSectionEventInterface::class
34
        );
35
36
        $parameters = [
37
            $this->createMock(ContentInfo::class),
38
            $this->createMock(Section::class),
39
        ];
40
41
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
42
43
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
44
        $service->assignSection(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignSection() misses a required argument $section.

This check looks for function calls that miss required arguments.

Loading history...
45
46
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
47
48
        $this->assertSame($calledListeners, [
49
            [BeforeAssignSectionEventInterface::class, 0],
50
            [AssignSectionEventInterface::class, 0],
51
        ]);
52
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
53
    }
54
55 View Code Duplication
    public function testAssignSectionStopPropagationInBeforeEvents()
56
    {
57
        $traceableEventDispatcher = $this->getEventDispatcher(
58
            BeforeAssignSectionEventInterface::class,
59
            AssignSectionEventInterface::class
60
        );
61
62
        $parameters = [
63
            $this->createMock(ContentInfo::class),
64
            $this->createMock(Section::class),
65
        ];
66
67
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
68
69
        $traceableEventDispatcher->addListener(BeforeAssignSectionEventInterface::class, function (BeforeAssignSectionEventInterface $event) {
70
            $event->stopPropagation();
71
        }, 10);
72
73
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
74
        $service->assignSection(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignSection() misses a required argument $section.

This check looks for function calls that miss required arguments.

Loading history...
75
76
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
77
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
78
79
        $this->assertSame($calledListeners, [
80
            [BeforeAssignSectionEventInterface::class, 10],
81
        ]);
82
        $this->assertSame($notCalledListeners, [
83
            [AssignSectionEventInterface::class, 0],
84
            [BeforeAssignSectionEventInterface::class, 0],
85
        ]);
86
    }
87
88 View Code Duplication
    public function testUpdateSectionEvents()
89
    {
90
        $traceableEventDispatcher = $this->getEventDispatcher(
91
            BeforeUpdateSectionEventInterface::class,
92
            UpdateSectionEventInterface::class
93
        );
94
95
        $parameters = [
96
            $this->createMock(Section::class),
97
            $this->createMock(SectionUpdateStruct::class),
98
        ];
99
100
        $updatedSection = $this->createMock(Section::class);
101
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
102
        $innerServiceMock->method('updateSection')->willReturn($updatedSection);
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...
103
104
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
105
        $result = $service->updateSection(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateSection() misses a required argument $sectionUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
106
107
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
108
109
        $this->assertSame($updatedSection, $result);
110
        $this->assertSame($calledListeners, [
111
            [BeforeUpdateSectionEventInterface::class, 0],
112
            [UpdateSectionEventInterface::class, 0],
113
        ]);
114
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
115
    }
116
117 View Code Duplication
    public function testReturnUpdateSectionResultInBeforeEvents()
118
    {
119
        $traceableEventDispatcher = $this->getEventDispatcher(
120
            BeforeUpdateSectionEventInterface::class,
121
            UpdateSectionEventInterface::class
122
        );
123
124
        $parameters = [
125
            $this->createMock(Section::class),
126
            $this->createMock(SectionUpdateStruct::class),
127
        ];
128
129
        $updatedSection = $this->createMock(Section::class);
130
        $eventUpdatedSection = $this->createMock(Section::class);
131
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
132
        $innerServiceMock->method('updateSection')->willReturn($updatedSection);
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...
133
134
        $traceableEventDispatcher->addListener(BeforeUpdateSectionEventInterface::class, function (BeforeUpdateSectionEventInterface $event) use ($eventUpdatedSection) {
135
            $event->setUpdatedSection($eventUpdatedSection);
136
        }, 10);
137
138
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
139
        $result = $service->updateSection(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateSection() misses a required argument $sectionUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
140
141
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
142
143
        $this->assertSame($eventUpdatedSection, $result);
144
        $this->assertSame($calledListeners, [
145
            [BeforeUpdateSectionEventInterface::class, 10],
146
            [BeforeUpdateSectionEventInterface::class, 0],
147
            [UpdateSectionEventInterface::class, 0],
148
        ]);
149
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
150
    }
151
152 View Code Duplication
    public function testUpdateSectionStopPropagationInBeforeEvents()
153
    {
154
        $traceableEventDispatcher = $this->getEventDispatcher(
155
            BeforeUpdateSectionEventInterface::class,
156
            UpdateSectionEventInterface::class
157
        );
158
159
        $parameters = [
160
            $this->createMock(Section::class),
161
            $this->createMock(SectionUpdateStruct::class),
162
        ];
163
164
        $updatedSection = $this->createMock(Section::class);
165
        $eventUpdatedSection = $this->createMock(Section::class);
166
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
167
        $innerServiceMock->method('updateSection')->willReturn($updatedSection);
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...
168
169
        $traceableEventDispatcher->addListener(BeforeUpdateSectionEventInterface::class, function (BeforeUpdateSectionEventInterface $event) use ($eventUpdatedSection) {
170
            $event->setUpdatedSection($eventUpdatedSection);
171
            $event->stopPropagation();
172
        }, 10);
173
174
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
175
        $result = $service->updateSection(...$parameters);
0 ignored issues
show
Bug introduced by
The call to updateSection() misses a required argument $sectionUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
176
177
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
178
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
179
180
        $this->assertSame($eventUpdatedSection, $result);
181
        $this->assertSame($calledListeners, [
182
            [BeforeUpdateSectionEventInterface::class, 10],
183
        ]);
184
        $this->assertSame($notCalledListeners, [
185
            [BeforeUpdateSectionEventInterface::class, 0],
186
            [UpdateSectionEventInterface::class, 0],
187
        ]);
188
    }
189
190
    public function testAssignSectionToSubtreeEvents()
191
    {
192
        $traceableEventDispatcher = $this->getEventDispatcher(
193
            BeforeAssignSectionToSubtreeEventInterface::class,
194
            AssignSectionToSubtreeEventInterface::class
195
        );
196
197
        $parameters = [
198
            $this->createMock(Location::class),
199
            $this->createMock(Section::class),
200
        ];
201
202
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
203
204
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
205
        $service->assignSectionToSubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignSectionToSubtree() misses a required argument $section.

This check looks for function calls that miss required arguments.

Loading history...
206
207
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
208
209
        $this->assertSame($calledListeners, [
210
            [BeforeAssignSectionToSubtreeEventInterface::class, 0],
211
            [AssignSectionToSubtreeEventInterface::class, 0],
212
        ]);
213
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
214
    }
215
216 View Code Duplication
    public function testAssignSectionToSubtreeStopPropagationInBeforeEvents()
217
    {
218
        $traceableEventDispatcher = $this->getEventDispatcher(
219
            BeforeAssignSectionToSubtreeEventInterface::class,
220
            AssignSectionToSubtreeEventInterface::class
221
        );
222
223
        $parameters = [
224
            $this->createMock(Location::class),
225
            $this->createMock(Section::class),
226
        ];
227
228
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
229
230
        $traceableEventDispatcher->addListener(BeforeAssignSectionToSubtreeEventInterface::class, function (BeforeAssignSectionToSubtreeEventInterface $event) {
231
            $event->stopPropagation();
232
        }, 10);
233
234
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
235
        $service->assignSectionToSubtree(...$parameters);
0 ignored issues
show
Bug introduced by
The call to assignSectionToSubtree() misses a required argument $section.

This check looks for function calls that miss required arguments.

Loading history...
236
237
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
238
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
239
240
        $this->assertSame($calledListeners, [
241
            [BeforeAssignSectionToSubtreeEventInterface::class, 10],
242
        ]);
243
        $this->assertSame($notCalledListeners, [
244
            [AssignSectionToSubtreeEventInterface::class, 0],
245
            [BeforeAssignSectionToSubtreeEventInterface::class, 0],
246
        ]);
247
    }
248
249
    public function testDeleteSectionEvents()
250
    {
251
        $traceableEventDispatcher = $this->getEventDispatcher(
252
            BeforeDeleteSectionEventInterface::class,
253
            DeleteSectionEventInterface::class
254
        );
255
256
        $parameters = [
257
            $this->createMock(Section::class),
258
        ];
259
260
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
261
262
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
263
        $service->deleteSection(...$parameters);
264
265
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
266
267
        $this->assertSame($calledListeners, [
268
            [BeforeDeleteSectionEventInterface::class, 0],
269
            [DeleteSectionEventInterface::class, 0],
270
        ]);
271
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
272
    }
273
274
    public function testDeleteSectionStopPropagationInBeforeEvents()
275
    {
276
        $traceableEventDispatcher = $this->getEventDispatcher(
277
            BeforeDeleteSectionEventInterface::class,
278
            DeleteSectionEventInterface::class
279
        );
280
281
        $parameters = [
282
            $this->createMock(Section::class),
283
        ];
284
285
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
286
287
        $traceableEventDispatcher->addListener(BeforeDeleteSectionEventInterface::class, function (BeforeDeleteSectionEventInterface $event) {
288
            $event->stopPropagation();
289
        }, 10);
290
291
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
292
        $service->deleteSection(...$parameters);
293
294
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
295
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
296
297
        $this->assertSame($calledListeners, [
298
            [BeforeDeleteSectionEventInterface::class, 10],
299
        ]);
300
        $this->assertSame($notCalledListeners, [
301
            [BeforeDeleteSectionEventInterface::class, 0],
302
            [DeleteSectionEventInterface::class, 0],
303
        ]);
304
    }
305
306 View Code Duplication
    public function testCreateSectionEvents()
307
    {
308
        $traceableEventDispatcher = $this->getEventDispatcher(
309
            BeforeCreateSectionEventInterface::class,
310
            CreateSectionEventInterface::class
311
        );
312
313
        $parameters = [
314
            $this->createMock(SectionCreateStruct::class),
315
        ];
316
317
        $section = $this->createMock(Section::class);
318
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
319
        $innerServiceMock->method('createSection')->willReturn($section);
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...
320
321
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
322
        $result = $service->createSection(...$parameters);
323
324
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
325
326
        $this->assertSame($section, $result);
327
        $this->assertSame($calledListeners, [
328
            [BeforeCreateSectionEventInterface::class, 0],
329
            [CreateSectionEventInterface::class, 0],
330
        ]);
331
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
332
    }
333
334 View Code Duplication
    public function testReturnCreateSectionResultInBeforeEvents()
335
    {
336
        $traceableEventDispatcher = $this->getEventDispatcher(
337
            BeforeCreateSectionEventInterface::class,
338
            CreateSectionEventInterface::class
339
        );
340
341
        $parameters = [
342
            $this->createMock(SectionCreateStruct::class),
343
        ];
344
345
        $section = $this->createMock(Section::class);
346
        $eventSection = $this->createMock(Section::class);
347
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
348
        $innerServiceMock->method('createSection')->willReturn($section);
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...
349
350
        $traceableEventDispatcher->addListener(BeforeCreateSectionEventInterface::class, function (BeforeCreateSectionEventInterface $event) use ($eventSection) {
351
            $event->setSection($eventSection);
352
        }, 10);
353
354
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
355
        $result = $service->createSection(...$parameters);
356
357
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
358
359
        $this->assertSame($eventSection, $result);
360
        $this->assertSame($calledListeners, [
361
            [BeforeCreateSectionEventInterface::class, 10],
362
            [BeforeCreateSectionEventInterface::class, 0],
363
            [CreateSectionEventInterface::class, 0],
364
        ]);
365
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
366
    }
367
368 View Code Duplication
    public function testCreateSectionStopPropagationInBeforeEvents()
369
    {
370
        $traceableEventDispatcher = $this->getEventDispatcher(
371
            BeforeCreateSectionEventInterface::class,
372
            CreateSectionEventInterface::class
373
        );
374
375
        $parameters = [
376
            $this->createMock(SectionCreateStruct::class),
377
        ];
378
379
        $section = $this->createMock(Section::class);
380
        $eventSection = $this->createMock(Section::class);
381
        $innerServiceMock = $this->createMock(SectionServiceInterface::class);
382
        $innerServiceMock->method('createSection')->willReturn($section);
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...
383
384
        $traceableEventDispatcher->addListener(BeforeCreateSectionEventInterface::class, function (BeforeCreateSectionEventInterface $event) use ($eventSection) {
385
            $event->setSection($eventSection);
386
            $event->stopPropagation();
387
        }, 10);
388
389
        $service = new SectionService($innerServiceMock, $traceableEventDispatcher);
390
        $result = $service->createSection(...$parameters);
391
392
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
393
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
394
395
        $this->assertSame($eventSection, $result);
396
        $this->assertSame($calledListeners, [
397
            [BeforeCreateSectionEventInterface::class, 10],
398
        ]);
399
        $this->assertSame($notCalledListeners, [
400
            [BeforeCreateSectionEventInterface::class, 0],
401
            [CreateSectionEventInterface::class, 0],
402
        ]);
403
    }
404
}
405