Skip to content

Commit

Permalink
Merge pull request #138 from leroy-merlin-br/update-one-by-query
Browse files Browse the repository at this point in the history
Fix Bulk Writefilter handler
  • Loading branch information
ravanscafi committed Nov 12, 2018
2 parents d256cef + f6ac773 commit 56005ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Mongolid/DataMapper/BulkWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function updateOne(
array $options = ['upsert' => true],
string $operator = '$set'
) {
$filter = is_array($filter) ?: ['_id' => $filter];
$filter = is_array($filter) ? $filter : ['_id' => $filter];

return $this->getBulkWrite()->update(
$filter,
Expand Down
31 changes: 25 additions & 6 deletions tests/Mongolid/DataMapper/BulkWriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,19 @@ public function testShouldUpdateOneWithUnsetOperationToBulkWrite()
->withNoArgs()
->once();

$mongoBulkWrite->shouldReceive('update')
->with(['_id' => $id], ['$unset' => $data], ['upsert' => true])
->once();
$mongoBulkWrite->expects()
->update(
m::on(
function ($actual) {
$this->assertSame(['_id' => '123'], $actual);

return true;
}
),
['$unset' => $data],
['upsert' => true]
);


$bulkWrite = m::mock(BulkWrite::class.'[getBulkWrite]', [$entity]);

Expand All @@ -126,9 +136,18 @@ public function testShouldUpdateOneWithQueryOnFilterToBulkWrite()
->withNoArgs()
->once();

$mongoBulkWrite->shouldReceive('update')
->with($query, ['$unset' => $data], ['upsert' => true])
->once();
$mongoBulkWrite->expects()
->update(
m::on(
function ($actual) use ($query) {
$this->assertSame($query, $actual);

return true;
}
),
['$unset' => $data],
['upsert' => true]
);

$bulkWrite = m::mock(BulkWrite::class.'[getBulkWrite]', [$entity]);

Expand Down

0 comments on commit 56005ec

Please sign in to comment.