Code Duplication    Length = 47-51 lines in 2 locations

eZ/Publish/Core/Persistence/Cache/Tests/UserHandlerTest.php 2 locations

@@ 282-332 (lines=51) @@
279
    /**
280
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
281
     */
282
    public function testLoadRoleAssignmentsByGroupIdIsMiss()
283
    {
284
        $this->loggerMock->expects($this->once())->method('logCall');
285
286
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
287
        $this->cacheMock
288
            ->expects($this->once())
289
            ->method('getItem')
290
            ->with('user', 'role', 'assignments', 'byGroup', 42)
291
            ->will($this->returnValue($cacheItemMock));
292
293
        $cacheItemMock
294
            ->expects($this->once())
295
            ->method('get')
296
            ->will($this->returnValue(null));
297
298
        $cacheItemMock
299
            ->expects($this->once())
300
            ->method('isMiss')
301
            ->will($this->returnValue(true));
302
303
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler');
304
        $this->persistenceHandlerMock
305
            ->expects($this->once())
306
            ->method('userHandler')
307
            ->will($this->returnValue($innerHandlerMock));
308
309
        $innerHandlerMock
310
            ->expects($this->once())
311
            ->method('loadRoleAssignmentsByGroupId')
312
            ->with(42, false)
313
            ->will(
314
                $this->returnValue(
315
                    array(
316
                        new RoleAssignment(array('roleId' => 33)),
317
                    )
318
                )
319
            );
320
321
        $cacheItemMock
322
            ->expects($this->once())
323
            ->method('set')
324
            ->with($this->isType('array'));
325
326
        $handler = $this->persistenceCacheHandler->userHandler();
327
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42);
328
329
        $this->assertEquals(1, count($roleAssignments));
330
        $this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]);
331
        $this->assertEquals(33, $roleAssignments[0]->roleId);
332
    }
333
334
    /**
335
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
@@ 379-425 (lines=47) @@
376
    /**
377
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
378
     */
379
    public function testLoadRoleAssignmentsByGroupIdInheritedIsMiss()
380
    {
381
        $this->loggerMock->expects($this->once())->method('logCall');
382
383
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
384
        $this->cacheMock
385
            ->expects($this->once())
386
            ->method('getItem')
387
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', '42')
388
            ->will($this->returnValue($cacheItemMock));
389
390
        $cacheItemMock
391
            ->expects($this->once())
392
            ->method('get')
393
            ->will($this->returnValue(null));
394
395
        $cacheItemMock
396
            ->expects($this->once())
397
            ->method('isMiss')
398
            ->will($this->returnValue(true));
399
400
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler');
401
        $this->persistenceHandlerMock
402
            ->expects($this->once())
403
            ->method('userHandler')
404
            ->will($this->returnValue($innerHandlerMock));
405
406
        $innerHandlerMock
407
            ->expects($this->once())
408
            ->method('loadRoleAssignmentsByGroupId')
409
            ->with(42, true)
410
            ->will(
411
                $this->returnValue(array(new RoleAssignment(array('roleId' => 33))))
412
            );
413
414
        $cacheItemMock
415
            ->expects($this->once())
416
            ->method('set')
417
            ->with($this->isType('array'));
418
419
        $handler = $this->persistenceCacheHandler->userHandler();
420
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42, true);
421
422
        $this->assertEquals(1, count($roleAssignments));
423
        $this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]);
424
        $this->assertEquals(33, $roleAssignments[0]->roleId);
425
    }
426
427
    /**
428
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId