55use MongoDB \BulkWriteResult ;
66use MongoDB \Driver \BulkWrite as Bulk ;
77use MongoDB \Driver \WriteConcern ;
8+ use MongoDB \Model \BSONDocument ;
89use MongoDB \Operation \BulkWrite ;
910
1011class BulkWriteFunctionalTest extends FunctionalTestCase
@@ -23,21 +24,27 @@ public function testInserts()
2324 $ ops = [
2425 ['insertOne ' => [['_id ' => 1 , 'x ' => 11 ]]],
2526 ['insertOne ' => [['x ' => 22 ]]],
27+ ['insertOne ' => [(object ) ['_id ' => 'foo ' , 'x ' => 33 ]]],
28+ ['insertOne ' => [new BSONDocument (['_id ' => 'bar ' , 'x ' => 44 ])]],
2629 ];
2730
2831 $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
2932 $ result = $ operation ->execute ($ this ->getPrimaryServer ());
3033
3134 $ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
32- $ this ->assertSame (2 , $ result ->getInsertedCount ());
35+ $ this ->assertSame (4 , $ result ->getInsertedCount ());
3336
3437 $ insertedIds = $ result ->getInsertedIds ();
3538 $ this ->assertSame (1 , $ insertedIds [0 ]);
3639 $ this ->assertInstanceOf ('MongoDB\BSON\ObjectId ' , $ insertedIds [1 ]);
40+ $ this ->assertSame ('foo ' , $ insertedIds [2 ]);
41+ $ this ->assertSame ('bar ' , $ insertedIds [3 ]);
3742
3843 $ expected = [
39- ['_id ' => $ insertedIds [ 0 ] , 'x ' => 11 ],
44+ ['_id ' => 1 , 'x ' => 11 ],
4045 ['_id ' => $ insertedIds [1 ], 'x ' => 22 ],
46+ ['_id ' => 'foo ' , 'x ' => 33 ],
47+ ['_id ' => 'bar ' , 'x ' => 44 ],
4148 ];
4249
4350 $ this ->assertSameDocuments ($ expected , $ this ->collection ->find ());
0 commit comments