PHPLIB-242: Refactor FindAndModify to use field path syntax in type map

parent e0908555
......@@ -216,21 +216,14 @@ class FindAndModify implements Executable, Explainable
}
$cursor = $server->executeWriteCommand($this->databaseName, new Command($this->createCommandDocument($server)), $this->createOptions());
$result = current($cursor->toArray());
if ( ! isset($result->value)) {
return null;
}
if ( ! is_object($result->value)) {
throw new UnexpectedValueException('findAndModify command did not return a "value" document');
}
if (isset($this->options['typeMap'])) {
return \MongoDB\apply_type_map_to_document($result->value, $this->options['typeMap']);
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'value'));
}
return $result->value;
$result = current($cursor->toArray());
return isset($result->value) ? $result->value : null;
}
public function getCommandDocument(Server $server)
......
......@@ -58,6 +58,40 @@ class FunctionsTest extends TestCase
'z' => new BSONArray([1, 2, 3]),
]),
],
[
[
'x' => 1,
'random' => [
'foo' => 'bar',
],
'value' => [
'bar' => 'baz',
'embedded' => [
'foo' => 'bar',
],
],
],
[
'root' => 'array',
'document' => 'stdClass',
'array' => 'array',
'fieldPaths' => [
'value' => 'array',
],
],
[
'x' => 1,
'random' => (object) [
'foo' => 'bar',
],
'value' => [
'bar' => 'baz',
'embedded' => (object) [
'foo' => 'bar',
],
],
],
]
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment