Code Duplication    Length = 53-57 lines in 2 locations

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

@@ 288-344 (lines=57) @@
285
    /**
286
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
287
     */
288
    public function testLoadRoleAssignmentsByGroupIdIsMiss()
289
    {
290
        $this->loggerMock->expects($this->once())->method('logCall');
291
292
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
293
        $this->cacheMock
294
            ->expects($this->once())
295
            ->method('getItem')
296
            ->with('user', 'role', 'assignments', 'byGroup', 42)
297
            ->will($this->returnValue($cacheItemMock));
298
299
        $cacheItemMock
300
            ->expects($this->once())
301
            ->method('get')
302
            ->will($this->returnValue(null));
303
304
        $cacheItemMock
305
            ->expects($this->once())
306
            ->method('isMiss')
307
            ->will($this->returnValue(true));
308
309
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler');
310
        $this->persistenceHandlerMock
311
            ->expects($this->once())
312
            ->method('userHandler')
313
            ->will($this->returnValue($innerHandlerMock));
314
315
        $innerHandlerMock
316
            ->expects($this->once())
317
            ->method('loadRoleAssignmentsByGroupId')
318
            ->with(42, false)
319
            ->will(
320
                $this->returnValue(
321
                    array(
322
                        new RoleAssignment(array('roleId' => 33)),
323
                    )
324
                )
325
            );
326
327
        $cacheItemMock
328
            ->expects($this->once())
329
            ->method('set')
330
            ->with($this->isType('array'))
331
            ->will($this->returnValue($cacheItemMock));
332
333
        $cacheItemMock
334
            ->expects($this->once())
335
            ->method('save')
336
            ->with();
337
338
        $handler = $this->persistenceCacheHandler->userHandler();
339
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42);
340
341
        $this->assertEquals(1, count($roleAssignments));
342
        $this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]);
343
        $this->assertEquals(33, $roleAssignments[0]->roleId);
344
    }
345
346
    /**
347
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
@@ 391-443 (lines=53) @@
388
    /**
389
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
390
     */
391
    public function testLoadRoleAssignmentsByGroupIdInheritedIsMiss()
392
    {
393
        $this->loggerMock->expects($this->once())->method('logCall');
394
395
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
396
        $this->cacheMock
397
            ->expects($this->once())
398
            ->method('getItem')
399
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', '42')
400
            ->will($this->returnValue($cacheItemMock));
401
402
        $cacheItemMock
403
            ->expects($this->once())
404
            ->method('get')
405
            ->will($this->returnValue(null));
406
407
        $cacheItemMock
408
            ->expects($this->once())
409
            ->method('isMiss')
410
            ->will($this->returnValue(true));
411
412
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler');
413
        $this->persistenceHandlerMock
414
            ->expects($this->once())
415
            ->method('userHandler')
416
            ->will($this->returnValue($innerHandlerMock));
417
418
        $innerHandlerMock
419
            ->expects($this->once())
420
            ->method('loadRoleAssignmentsByGroupId')
421
            ->with(42, true)
422
            ->will(
423
                $this->returnValue(array(new RoleAssignment(array('roleId' => 33))))
424
            );
425
426
        $cacheItemMock
427
            ->expects($this->once())
428
            ->method('set')
429
            ->with($this->isType('array'))
430
            ->will($this->returnValue($cacheItemMock));
431
432
        $cacheItemMock
433
            ->expects($this->once())
434
            ->method('save')
435
            ->with();
436
437
        $handler = $this->persistenceCacheHandler->userHandler();
438
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42, true);
439
440
        $this->assertEquals(1, count($roleAssignments));
441
        $this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]);
442
        $this->assertEquals(33, $roleAssignments[0]->roleId);
443
    }
444
445
    /**
446
     * @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId