Skip to content

Commit

Permalink
Fix findAndModify when specifying update param and option
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 3, 2016
1 parent 4fd36a2 commit d3c52dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mongo/MongoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public function findAndModify(array $query, array $update = null, array $fields
} else {
$update = is_array($update) ? $update : [];
if (isset($options['update']) && is_array($options['update'])) {
$update = array_merge($update, $options['update']);
$update = $options['update'];
unset($options['update']);
}

Expand Down
29 changes: 29 additions & 0 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,35 @@ public function testFindAndModifyUpdateWithUpdateOptions()
$this->assertObjectNotHasAttribute('foo', $object);
}

public function testFindAndModifyWithUpdateParamAndOption()
{
$id = '54203e08d51d4a1f868b456e';
$collection = $this->getCollection();

$document = ['_id' => new \MongoId($id), 'foo' => 'bar'];
$collection->insert($document);

$data = ['foo' => 'foo', 'bar' => 'bar'];

$this->getCollection()->findAndModify(
['_id' => new \MongoId($id)],
[$data],
[],
[
'update' => ['$set' => ['foo' => 'foobar']],
'upsert' => true,
]
);

$newCollection = $this->getCheckDatabase()->selectCollection('test');
$this->assertSame(1, $newCollection->count());
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeSame('foobar', 'foo', $object);
$this->assertObjectNotHasAttribute('bar', $object);
}

public function testFindAndModifyUpdateReplace()
{
$id = '54203e08d51d4a1f868b456e';
Expand Down

0 comments on commit d3c52dd

Please sign in to comment.