Skip to content

Commit 383f90a

Browse files
committed
PHPLIB-481: Add functional test for pipeline-style bulk updates
1 parent ff4ced9 commit 383f90a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/Operation/BulkWriteFunctionalTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,36 @@ function (array $event) {
295295
);
296296
}
297297

298+
public function testBulkWriteWithPipelineUpdates()
299+
{
300+
if (version_compare($this->getServerVersion(), '4.2.0', '<')) {
301+
$this->markTestSkipped('Pipeline-style updates are not supported');
302+
}
303+
304+
$this->createFixtures(4);
305+
306+
$ops = [
307+
['updateOne' => [['_id' => 2], [['$addFields' => ['y' => 2]]]]],
308+
['updateMany' => [['_id' => ['$gt' => 2]], [['$addFields' => ['y' => '$_id']]]]],
309+
];
310+
311+
$operation = new BulkWrite($this->getDatabaseName(), $this->getCollectionName(), $ops);
312+
$result = $operation->execute($this->getPrimaryServer());
313+
314+
$this->assertInstanceOf(BulkWriteResult::class, $result);
315+
$this->assertSame(3, $result->getMatchedCount());
316+
$this->assertSame(3, $result->getModifiedCount());
317+
318+
$expected = [
319+
['_id' => 1, 'x' => 11],
320+
['_id' => 2, 'x' => 22, 'y' => 2],
321+
['_id' => 3, 'x' => 33, 'y' => 3],
322+
['_id' => 4, 'x' => 44, 'y' => 4],
323+
];
324+
325+
$this->assertSameDocuments($expected, $this->collection->find());
326+
}
327+
298328
/**
299329
* Create data fixtures.
300330
*

0 commit comments

Comments
 (0)