public function testShouldGetCursorFromDatabaseAndCacheForLater()
{
// Arrange
$documentsFromDb = [['name' => 'joe'], ['name' => 'doe']];
$cursor = $this->getCachableCursor()->limit(150);
$cacheComponent = m::mock(CacheComponentInterface::class);
$rawCollection = m::mock();
$this->setProtected($cursor, 'collection', $rawCollection);
// Act
$cursor->shouldReceive('generateCacheKey')->andReturn('find:collection:123');
Ioc::instance(CacheComponentInterface::class, $cacheComponent);
$cacheComponent->shouldReceive('get')->with('find:collection:123', null)->andReturn(null);
$rawCollection->shouldReceive('find')->with([], ['limit' => 100])->andReturn(new ArrayIterator($documentsFromDb));
$cacheComponent->shouldReceive('put')->once()->with('find:collection:123', $documentsFromDb, m::any());
// Assert
$this->assertEquals(new ArrayIterator($documentsFromDb), $this->callProtected($cursor, 'getCursor'));
}