Mongolid\DataMapper\DataMapperTest::testShouldGetFirstTroughACacheableCursorProjectingFields PHP Method

testShouldGetFirstTroughACacheableCursorProjectingFields() public method

    public function testShouldGetFirstTroughACacheableCursorProjectingFields()
    {
        // Arrange
        $connPool = m::mock(Pool::class);
        $mapper = m::mock(DataMapper::class . '[where]', [$connPool]);
        $query = 123;
        $entity = new stdClass();
        $cursor = m::mock(CacheableCursor::class);
        $projection = ['project' => true, '_id' => false];
        // Expect
        $mapper->shouldReceive('where')->once()->with($query, $projection, true)->andReturn($cursor);
        $cursor->shouldReceive('first')->once()->andReturn($entity);
        // Act
        $result = $mapper->first($query, $projection, true);
        // Assert
        $this->assertEquals($entity, $result);
    }