public function testShouldGetFirstWithQuery()
{
// Arrange
$connPool = m::mock(Pool::class);
$mapper = m::mock(DataMapper::class . '[prepareValueQuery,getCollection]', [$connPool]);
$schema = m::mock(Schema::class);
$converter = m::mock(Converter::class . '[toDomainTypes]');
$collection = m::mock(Collection::class);
$query = 123;
$preparedQuery = ['_id' => 123];
$schema->entityClass = 'stdClass';
$mapper->setSchema($schema);
$mapper->shouldAllowMockingProtectedMethods();
// Act
Ioc::instance(Converter::class, $converter);
$mapper->shouldReceive('prepareValueQuery')->once()->with($query)->andReturn($preparedQuery);
$mapper->shouldReceive('getCollection')->once()->andReturn($collection);
$collection->shouldReceive('findOne')->once()->with($preparedQuery, ['projection' => []])->andReturn(['name' => 'John Doe']);
$converter->shouldReceive('toDomainTypes')->once()->with(['name' => 'John Doe'])->passthru();
$result = $mapper->first($query);
// Assert
$this->assertInstanceOf(stdClass::class, $result);
$this->assertAttributeEquals('John Doe', 'name', $result);
}