5
5
use MongoDB \BulkWriteResult ;
6
6
use MongoDB \Driver \BulkWrite as Bulk ;
7
7
use MongoDB \Driver \WriteConcern ;
8
+ use MongoDB \Model \BSONDocument ;
8
9
use MongoDB \Operation \BulkWrite ;
9
10
10
11
class BulkWriteFunctionalTest extends FunctionalTestCase
@@ -23,21 +24,27 @@ public function testInserts()
23
24
$ ops = [
24
25
['insertOne ' => [['_id ' => 1 , 'x ' => 11 ]]],
25
26
['insertOne ' => [['x ' => 22 ]]],
27
+ ['insertOne ' => [(object ) ['_id ' => 'foo ' , 'x ' => 33 ]]],
28
+ ['insertOne ' => [new BSONDocument (['_id ' => 'bar ' , 'x ' => 44 ])]],
26
29
];
27
30
28
31
$ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
29
32
$ result = $ operation ->execute ($ this ->getPrimaryServer ());
30
33
31
34
$ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
32
- $ this ->assertSame (2 , $ result ->getInsertedCount ());
35
+ $ this ->assertSame (4 , $ result ->getInsertedCount ());
33
36
34
37
$ insertedIds = $ result ->getInsertedIds ();
35
38
$ this ->assertSame (1 , $ insertedIds [0 ]);
36
39
$ this ->assertInstanceOf ('MongoDB\BSON\ObjectId ' , $ insertedIds [1 ]);
40
+ $ this ->assertSame ('foo ' , $ insertedIds [2 ]);
41
+ $ this ->assertSame ('bar ' , $ insertedIds [3 ]);
37
42
38
43
$ expected = [
39
- ['_id ' => $ insertedIds [ 0 ] , 'x ' => 11 ],
44
+ ['_id ' => 1 , 'x ' => 11 ],
40
45
['_id ' => $ insertedIds [1 ], 'x ' => 22 ],
46
+ ['_id ' => 'foo ' , 'x ' => 33 ],
47
+ ['_id ' => 'bar ' , 'x ' => 44 ],
41
48
];
42
49
43
50
$ this ->assertSameDocuments ($ expected , $ this ->collection ->find ());
0 commit comments