Code Duplication    Length = 38-40 lines in 3 locations

eZ/Publish/Core/Event/Tests/URLAliasServiceTest.php 2 locations

@@ 94-133 (lines=40) @@
91
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
92
    }
93
94
    public function testCreateGlobalUrlAliasStopPropagationInBeforeEvents()
95
    {
96
        $traceableEventDispatcher = $this->getEventDispatcher(
97
            BeforeCreateGlobalUrlAliasEventInterface::class,
98
            CreateGlobalUrlAliasEventInterface::class
99
        );
100
101
        $parameters = [
102
            'random_value_5cff79c3183a40.78467503',
103
            'random_value_5cff79c3183a52.60688594',
104
            'random_value_5cff79c3183a62.37338343',
105
            'random_value_5cff79c3183a74.31062414',
106
            'random_value_5cff79c3183a85.16422549',
107
        ];
108
109
        $urlAlias = $this->createMock(URLAlias::class);
110
        $eventUrlAlias = $this->createMock(URLAlias::class);
111
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
112
        $innerServiceMock->method('createGlobalUrlAlias')->willReturn($urlAlias);
113
114
        $traceableEventDispatcher->addListener(BeforeCreateGlobalUrlAliasEventInterface::class, function (BeforeCreateGlobalUrlAliasEventInterface $event) use ($eventUrlAlias) {
115
            $event->setUrlAlias($eventUrlAlias);
116
            $event->stopPropagation();
117
        }, 10);
118
119
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
120
        $result = $service->createGlobalUrlAlias(...$parameters);
121
122
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
123
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
124
125
        $this->assertSame($eventUrlAlias, $result);
126
        $this->assertSame($calledListeners, [
127
            [BeforeCreateGlobalUrlAliasEventInterface::class, 10],
128
        ]);
129
        $this->assertSame($notCalledListeners, [
130
            [BeforeCreateGlobalUrlAliasEventInterface::class, 0],
131
            [CreateGlobalUrlAliasEventInterface::class, 0],
132
        ]);
133
    }
134
135
    public function testRefreshSystemUrlAliasesForLocationEvents()
136
    {
@@ 262-301 (lines=40) @@
259
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
260
    }
261
262
    public function testCreateUrlAliasStopPropagationInBeforeEvents()
263
    {
264
        $traceableEventDispatcher = $this->getEventDispatcher(
265
            BeforeCreateUrlAliasEventInterface::class,
266
            CreateUrlAliasEventInterface::class
267
        );
268
269
        $parameters = [
270
            $this->createMock(Location::class),
271
            'random_value_5cff79c3185072.24449261',
272
            'random_value_5cff79c3185080.62311461',
273
            'random_value_5cff79c3185095.31877612',
274
            'random_value_5cff79c31850a4.20254218',
275
        ];
276
277
        $urlAlias = $this->createMock(URLAlias::class);
278
        $eventUrlAlias = $this->createMock(URLAlias::class);
279
        $innerServiceMock = $this->createMock(URLAliasServiceInterface::class);
280
        $innerServiceMock->method('createUrlAlias')->willReturn($urlAlias);
281
282
        $traceableEventDispatcher->addListener(BeforeCreateUrlAliasEventInterface::class, function (BeforeCreateUrlAliasEventInterface $event) use ($eventUrlAlias) {
283
            $event->setUrlAlias($eventUrlAlias);
284
            $event->stopPropagation();
285
        }, 10);
286
287
        $service = new URLAliasService($innerServiceMock, $traceableEventDispatcher);
288
        $result = $service->createUrlAlias(...$parameters);
289
290
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
291
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
292
293
        $this->assertSame($eventUrlAlias, $result);
294
        $this->assertSame($calledListeners, [
295
            [BeforeCreateUrlAliasEventInterface::class, 10],
296
        ]);
297
        $this->assertSame($notCalledListeners, [
298
            [BeforeCreateUrlAliasEventInterface::class, 0],
299
            [CreateUrlAliasEventInterface::class, 0],
300
        ]);
301
    }
302
303
    public function testRemoveAliasesEvents()
304
    {

eZ/Publish/Core/Event/Tests/URLWildcardServiceTest.php 1 location

@@ 145-182 (lines=38) @@
142
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
143
    }
144
145
    public function testCreateStopPropagationInBeforeEvents()
146
    {
147
        $traceableEventDispatcher = $this->getEventDispatcher(
148
            BeforeCreateEventInterface::class,
149
            CreateEventInterface::class
150
        );
151
152
        $parameters = [
153
            'random_value_5cff79c316c359.46056769',
154
            'random_value_5cff79c316c361.53134429',
155
            'random_value_5cff79c316c374.82657815',
156
        ];
157
158
        $urlWildcard = $this->createMock(URLWildcard::class);
159
        $eventUrlWildcard = $this->createMock(URLWildcard::class);
160
        $innerServiceMock = $this->createMock(URLWildcardServiceInterface::class);
161
        $innerServiceMock->method('create')->willReturn($urlWildcard);
162
163
        $traceableEventDispatcher->addListener(BeforeCreateEventInterface::class, function (BeforeCreateEventInterface $event) use ($eventUrlWildcard) {
164
            $event->setUrlWildcard($eventUrlWildcard);
165
            $event->stopPropagation();
166
        }, 10);
167
168
        $service = new URLWildcardService($innerServiceMock, $traceableEventDispatcher);
169
        $result = $service->create(...$parameters);
170
171
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
172
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
173
174
        $this->assertSame($eventUrlWildcard, $result);
175
        $this->assertSame($calledListeners, [
176
            [BeforeCreateEventInterface::class, 10],
177
        ]);
178
        $this->assertSame($notCalledListeners, [
179
            [BeforeCreateEventInterface::class, 0],
180
            [CreateEventInterface::class, 0],
181
        ]);
182
    }
183
184
    public function testTranslateEvents()
185
    {