Code Duplication    Length = 36-37 lines in 2 locations

eZ/Publish/Core/Repository/Tests/Service/Mock/UrlAliasTest.php 2 locations

@@ 214-249 (lines=36) @@
211
    /**
212
     * Test for the removeAliases() method.
213
     */
214
    public function testRemoveAliases()
215
    {
216
        $aliasList = array(new UrlAlias(array('isCustom' => true)));
217
        $spiAliasList = array(new SPIUrlAlias(array('isCustom' => true)));
218
        $permissionResolverMock = $this->createMock(PermissionResolver::class);
219
        $permissionResolverMock
220
            ->expects($this->once())
221
            ->method('hasAccess')->with(
222
                $this->equalTo('content'),
223
                $this->equalTo('urltranslator')
224
            )->will($this->returnValue(true));
225
226
        $repositoryMock = $this->getRepositoryMock();
227
228
        $repositoryMock
229
            ->expects($this->atLeastOnce())
230
            ->method('getPermissionResolver')
231
            ->willReturn($permissionResolverMock);
232
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
233
        /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */
234
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
235
236
        $repositoryMock
237
            ->expects($this->once())
238
            ->method('beginTransaction');
239
        $repositoryMock
240
            ->expects($this->once())
241
            ->method('commit');
242
243
        $urlAliasHandlerMock
244
            ->expects($this->once())
245
            ->method('removeURLAliases')
246
            ->with($spiAliasList);
247
248
        $mockedService->removeAliases($aliasList);
249
    }
250
251
    /**
252
     * Test for the removeAliases() method.
@@ 257-293 (lines=37) @@
254
     * @expectedException \Exception
255
     * @expectedExceptionMessage Handler threw an exception
256
     */
257
    public function testRemoveAliasesWithRollback()
258
    {
259
        $aliasList = array(new UrlAlias(array('isCustom' => true)));
260
        $spiAliasList = array(new SPIUrlAlias(array('isCustom' => true)));
261
        $permissionResolverMock = $this->createMock(PermissionResolver::class);
262
        $permissionResolverMock
263
            ->expects($this->once())
264
            ->method('hasAccess')->with(
265
                $this->equalTo('content'),
266
                $this->equalTo('urltranslator')
267
            )->will($this->returnValue(true));
268
269
        $repositoryMock = $this->getRepositoryMock();
270
271
        $repositoryMock
272
            ->expects($this->atLeastOnce())
273
            ->method('getPermissionResolver')
274
            ->willReturn($permissionResolverMock);
275
        $mockedService = $this->getPartlyMockedURLAliasServiceService();
276
        /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandlerMock */
277
        $urlAliasHandlerMock = $this->getPersistenceMock()->urlAliasHandler();
278
279
        $repositoryMock
280
            ->expects($this->once())
281
            ->method('beginTransaction');
282
        $repositoryMock
283
            ->expects($this->once())
284
            ->method('rollback');
285
286
        $urlAliasHandlerMock
287
            ->expects($this->once())
288
            ->method('removeURLAliases')
289
            ->with($spiAliasList)
290
            ->will($this->throwException(new Exception('Handler threw an exception')));
291
292
        $mockedService->removeAliases($aliasList);
293
    }
294
295
    public function providerForTestListAutogeneratedLocationAliasesPath()
296
    {