Code Duplication    Length = 40-40 lines in 2 locations

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

@@ 276-315 (lines=40) @@
273
     *
274
     * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById
275
     */
276
    public function testLoadVersionInfoByIdPublishedVersion()
277
    {
278
        $repository = $this->getRepositoryMock();
279
        $contentServiceMock = $this->getPartlyMockedContentService();
280
        /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */
281
        $contentHandler = $this->getPersistenceMock()->contentHandler();
282
        $domainMapperMock = $this->getDomainMapperMock();
283
        $versionInfoMock = $this->createMock(APIVersionInfo::class);
284
        $permissionResolver = $this->getPermissionResolverMock();
285
286
        $versionInfoMock->expects($this->once())
287
            ->method('isPublished')
288
            ->willReturn(true);
289
290
        $contentHandler->expects($this->once())
291
            ->method('loadVersionInfo')
292
            ->with(
293
                $this->equalTo(42),
294
                $this->equalTo(24)
295
            )->will(
296
                $this->returnValue(new SPIVersionInfo())
297
            );
298
299
        $domainMapperMock->expects($this->once())
300
            ->method('buildVersionInfoDomainObject')
301
            ->with(new SPIVersionInfo())
302
            ->will($this->returnValue($versionInfoMock));
303
304
        $permissionResolver->expects($this->once())
305
            ->method('canUser')
306
            ->with(
307
                $this->equalTo('content'),
308
                $this->equalTo('read'),
309
                $this->equalTo($versionInfoMock)
310
            )->will($this->returnValue(true));
311
312
        $result = $contentServiceMock->loadVersionInfoById(42, 24);
313
314
        $this->assertEquals($versionInfoMock, $result);
315
    }
316
317
    /**
318
     * Test for the loadVersionInfo() method.
@@ 322-361 (lines=40) @@
319
     *
320
     * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById
321
     */
322
    public function testLoadVersionInfoByIdNonPublishedVersion()
323
    {
324
        $repository = $this->getRepositoryMock();
325
        $contentServiceMock = $this->getPartlyMockedContentService();
326
        /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */
327
        $contentHandler = $this->getPersistenceMock()->contentHandler();
328
        $domainMapperMock = $this->getDomainMapperMock();
329
        $versionInfoMock = $this->createMock(APIVersionInfo::class);
330
        $permissionResolver = $this->getPermissionResolverMock();
331
332
        $versionInfoMock->expects($this->once())
333
            ->method('isPublished')
334
            ->willReturn(false);
335
336
        $contentHandler->expects($this->once())
337
            ->method('loadVersionInfo')
338
            ->with(
339
                $this->equalTo(42),
340
                $this->equalTo(24)
341
            )->will(
342
                $this->returnValue(new SPIVersionInfo())
343
            );
344
345
        $domainMapperMock->expects($this->once())
346
            ->method('buildVersionInfoDomainObject')
347
            ->with(new SPIVersionInfo())
348
            ->will($this->returnValue($versionInfoMock));
349
350
        $permissionResolver->expects($this->once())
351
            ->method('canUser')
352
            ->with(
353
                $this->equalTo('content'),
354
                $this->equalTo('versionread'),
355
                $this->equalTo($versionInfoMock)
356
            )->will($this->returnValue(true));
357
358
        $result = $contentServiceMock->loadVersionInfoById(42, 24);
359
360
        $this->assertEquals($versionInfoMock, $result);
361
    }
362
363
    /**
364
     * Test for the loadVersionInfo() method.