public function testShouldInsertWithoutFiringEvents($entity, $writeConcern, $shouldFireEventAfter, $expected)
{
// Arrange
$connPool = m::mock(Pool::class);
$mapper = m::mock(DataMapper::class . '[parseToDocument,getCollection]', [$connPool]);
$options = ['writeConcern' => new WriteConcern($writeConcern)];
$collection = m::mock(Collection::class);
$parsedObject = ['_id' => 123];
$operationResult = m::mock();
$entity->_id = null;
// Act
$mapper->shouldAllowMockingProtectedMethods();
$mapper->shouldReceive('parseToDocument')->once()->with($entity)->andReturn($parsedObject);
$mapper->shouldReceive('getCollection')->once()->andReturn($collection);
$collection->shouldReceive('insertOne')->once()->with($parsedObject, ['writeConcern' => new WriteConcern($writeConcern)])->andReturn($operationResult);
$operationResult->shouldReceive('isAcknowledged')->once()->andReturn((bool) $writeConcern);
$operationResult->shouldReceive('getInsertedCount')->andReturn(1);
if ($entity instanceof AttributesAccessInterface) {
$entity->shouldReceive('syncOriginalAttributes')->once()->with();
}
$this->expectEventNotToBeFired('inserting', $entity);
$this->expectEventNotToBeFired('inserted', $entity);
// Assert
$this->assertEquals($expected, $mapper->insert($entity, $options, false));
}