Code Duplication    Length = 38-40 lines in 3 locations

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

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

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

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