public function testShouldUpdate($entity, $writeConcern, $shouldFireEventAfter, $expected)
{
// Arrange
$connPool = m::mock(Pool::class);
$mapper = m::mock(DataMapper::class . '[parseToDocument,getCollection]', [$connPool]);
$collection = m::mock(Collection::class);
$parsedObject = ['_id' => 123];
$operationResult = m::mock();
$options = ['writeConcern' => new WriteConcern($writeConcern)];
$entity->_id = 123;
// Act
$mapper->shouldAllowMockingProtectedMethods();
$mapper->shouldReceive('parseToDocument')->once()->with($entity)->andReturn($parsedObject);
$mapper->shouldReceive('getCollection')->once()->andReturn($collection);
$collection->shouldReceive('updateOne')->once()->with(['_id' => 123], ['$set' => $parsedObject], ['writeConcern' => new WriteConcern($writeConcern)])->andReturn($operationResult);
$operationResult->shouldReceive('isAcknowledged')->once()->andReturn((bool) $writeConcern);
$operationResult->shouldReceive('getModifiedCount')->andReturn(1);
if ($entity instanceof AttributesAccessInterface) {
$entity->shouldReceive('syncOriginalAttributes')->once()->with();
}
$this->expectEventToBeFired('updating', $entity, true);
if ($shouldFireEventAfter) {
$this->expectEventToBeFired('updated', $entity, false);
} else {
$this->expectEventNotToBeFired('updated', $entity);
}
// Assert
$this->assertEquals($expected, $mapper->update($entity, $options));
}