Code Duplication    Length = 53-57 lines in 2 locations

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

@@ 299-355 (lines=57) @@
296
    /**
297
     * @covers \eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
298
     */
299
    public function testLoadRoleAssignmentsByGroupIdIsMiss()
300
    {
301
        $this->loggerMock->expects($this->once())->method('logCall');
302
303
        $cacheItemMock = $this->getCacheItemMock();
304
        $this->cacheMock
305
            ->expects($this->once())
306
            ->method('getItem')
307
            ->with('user', 'role', 'assignments', 'byGroup', 42)
308
            ->will($this->returnValue($cacheItemMock));
309
310
        $cacheItemMock
311
            ->expects($this->once())
312
            ->method('get')
313
            ->will($this->returnValue(null));
314
315
        $cacheItemMock
316
            ->expects($this->once())
317
            ->method('isMiss')
318
            ->will($this->returnValue(true));
319
320
        $innerHandlerMock = $this->getSPIUserHandlerMock();
321
        $this->persistenceHandlerMock
322
            ->expects($this->once())
323
            ->method('userHandler')
324
            ->will($this->returnValue($innerHandlerMock));
325
326
        $innerHandlerMock
327
            ->expects($this->once())
328
            ->method('loadRoleAssignmentsByGroupId')
329
            ->with(42, false)
330
            ->will(
331
                $this->returnValue(
332
                    array(
333
                        new RoleAssignment(array('roleId' => 33)),
334
                    )
335
                )
336
            );
337
338
        $cacheItemMock
339
            ->expects($this->once())
340
            ->method('set')
341
            ->with($this->isType('array'))
342
            ->will($this->returnValue($cacheItemMock));
343
344
        $cacheItemMock
345
            ->expects($this->once())
346
            ->method('save')
347
            ->with();
348
349
        $handler = $this->persistenceCacheHandler->userHandler();
350
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42);
351
352
        $this->assertEquals(1, count($roleAssignments));
353
        $this->assertInstanceOf(RoleAssignment::class, $roleAssignments[0]);
354
        $this->assertEquals(33, $roleAssignments[0]->roleId);
355
    }
356
357
    /**
358
     * @covers \eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
@@ 402-454 (lines=53) @@
399
    /**
400
     * @covers \eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId
401
     */
402
    public function testLoadRoleAssignmentsByGroupIdInheritedIsMiss()
403
    {
404
        $this->loggerMock->expects($this->once())->method('logCall');
405
406
        $cacheItemMock = $this->getCacheItemMock();
407
        $this->cacheMock
408
            ->expects($this->once())
409
            ->method('getItem')
410
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', '42')
411
            ->will($this->returnValue($cacheItemMock));
412
413
        $cacheItemMock
414
            ->expects($this->once())
415
            ->method('get')
416
            ->will($this->returnValue(null));
417
418
        $cacheItemMock
419
            ->expects($this->once())
420
            ->method('isMiss')
421
            ->will($this->returnValue(true));
422
423
        $innerHandlerMock = $this->getSPIUserHandlerMock();
424
        $this->persistenceHandlerMock
425
            ->expects($this->once())
426
            ->method('userHandler')
427
            ->will($this->returnValue($innerHandlerMock));
428
429
        $innerHandlerMock
430
            ->expects($this->once())
431
            ->method('loadRoleAssignmentsByGroupId')
432
            ->with(42, true)
433
            ->will(
434
                $this->returnValue(array(new RoleAssignment(array('roleId' => 33))))
435
            );
436
437
        $cacheItemMock
438
            ->expects($this->once())
439
            ->method('set')
440
            ->with($this->isType('array'))
441
            ->will($this->returnValue($cacheItemMock));
442
443
        $cacheItemMock
444
            ->expects($this->once())
445
            ->method('save')
446
            ->with();
447
448
        $handler = $this->persistenceCacheHandler->userHandler();
449
        $roleAssignments = $handler->loadRoleAssignmentsByGroupId(42, true);
450
451
        $this->assertEquals(1, count($roleAssignments));
452
        $this->assertInstanceOf(RoleAssignment::class, $roleAssignments[0]);
453
        $this->assertEquals(33, $roleAssignments[0]->roleId);
454
    }
455
456
    /**
457
     * @covers \eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId