public function testLoadAllGroupsCached($offset = 0, $limit = -1)
{
$testGroups = $this->generateObjectGroupsArray($offset, $limit);
$testGroupIds = array_map(function ($group) {
return $group->id;
}, $testGroups);
$cacheItemMock = $this->getMock('Stash\\Interfaces\\ItemInterface');
$this->cacheMock->expects($this->at(0))->method('getItem')->with('objectstategroup', 'all')->will($this->returnValue($cacheItemMock));
$cacheItemMock->expects($this->once())->method('get')->will($this->returnValue($testGroupIds));
$cacheItemMock->expects($this->once())->method('isMiss')->will($this->returnValue(false));
$expectedGroups = array_slice($testGroups, $offset, $limit > -1 ?: null);
// loadGroup()
foreach ($expectedGroups as $i => $group) {
$this->cacheMock->expects($this->at($i + 1))->method('getItem')->with('objectstategroup', $group->id)->will($this->returnCallback(function ($cachekey, $i) use($group) {
$cacheItemMock = $this->getMock('Stash\\Interfaces\\ItemInterface');
$cacheItemMock->expects($this->once())->method('get')->will($this->returnValue($group));
return $cacheItemMock;
}));
}
$handler = $this->persistenceCacheHandler->objectStateHandler();
$groups = $handler->loadAllGroups($offset, $limit);
$this->assertEquals($groups, $expectedGroups);
}