22
33namespace MongoDB \Tests \Collection ;
44
5- use MongoDB \Driver \BulkWrite ;
5+ use MongoDB \Driver \BulkWrite as Bulk ;
6+ use MongoDB \Operation \BulkWrite ;
67
78class BulkWriteFunctionalTest extends FunctionalTestCase
89{
@@ -22,7 +23,9 @@ public function testInserts()
2223 ['insertOne ' => [['x ' => 22 ]]],
2324 ];
2425
25- $ result = $ this ->collection ->bulkWrite ($ ops );
26+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
27+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
28+
2629 $ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
2730 $ this ->assertSame (2 , $ result ->getInsertedCount ());
2831
@@ -50,7 +53,9 @@ public function testUpdates()
5053 ['updateMany ' => [['x ' => ['$gt ' => 50 ]], ['$inc ' => ['x ' => 1 ]]]],
5154 ];
5255
53- $ result = $ this ->collection ->bulkWrite ($ ops );
56+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
57+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
58+
5459 $ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
5560 $ this ->assertSame (5 , $ result ->getMatchedCount ());
5661 $ this ->omitModifiedCount or $ this ->assertSame (5 , $ result ->getModifiedCount ());
@@ -81,7 +86,9 @@ public function testDeletes()
8186 ['deleteMany ' => [['_id ' => ['$gt ' => 2 ]]]],
8287 ];
8388
84- $ result = $ this ->collection ->bulkWrite ($ ops );
89+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
90+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
91+
8592 $ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
8693 $ this ->assertSame (3 , $ result ->getDeletedCount ());
8794
@@ -104,7 +111,9 @@ public function testMixedOrderedOperations()
104111 ['replaceOne ' => [['_id ' => 4 ], ['_id ' => 4 , 'x ' => 44 ], ['upsert ' => true ]]],
105112 ];
106113
107- $ result = $ this ->collection ->bulkWrite ($ ops );
114+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
115+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
116+
108117 $ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
109118
110119 $ this ->assertSame (1 , $ result ->getInsertedCount ());
@@ -132,7 +141,7 @@ public function testMixedOrderedOperations()
132141 */
133142 public function testUnknownOperation ()
134143 {
135- $ this ->collection -> bulkWrite ( [
144+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
136145 ['foo ' => [['_id ' => 1 ]]],
137146 ]);
138147 }
@@ -144,7 +153,7 @@ public function testUnknownOperation()
144153 */
145154 public function testMissingArguments (array $ ops )
146155 {
147- $ this ->collection -> bulkWrite ( $ ops );
156+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), $ ops );
148157 }
149158
150159 public function provideOpsWithMissingArguments ()
@@ -168,7 +177,7 @@ public function provideOpsWithMissingArguments()
168177 */
169178 public function testUpdateOneRequiresUpdateOperators ()
170179 {
171- $ this ->collection -> bulkWrite ( [
180+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
172181 ['updateOne ' => [['_id ' => 1 ], ['x ' => 1 ]]],
173182 ]);
174183 }
@@ -179,7 +188,7 @@ public function testUpdateOneRequiresUpdateOperators()
179188 */
180189 public function testUpdateManyRequiresUpdateOperators ()
181190 {
182- $ this ->collection -> bulkWrite ( [
191+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
183192 ['updateMany ' => [['_id ' => ['$gt ' => 1 ]], ['x ' => 1 ]]],
184193 ]);
185194 }
@@ -190,7 +199,7 @@ public function testUpdateManyRequiresUpdateOperators()
190199 */
191200 public function testReplaceOneRequiresReplacementDocument ()
192201 {
193- $ this ->collection -> bulkWrite ( [
202+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
194203 ['replaceOne ' => [['_id ' => 1 ], ['$inc ' => ['x ' => 1 ]]]],
195204 ]);
196205 }
@@ -202,7 +211,7 @@ public function testReplaceOneRequiresReplacementDocument()
202211 */
203212 private function createFixtures ($ n )
204213 {
205- $ bulkWrite = new BulkWrite (['ordered ' => true ]);
214+ $ bulkWrite = new Bulk (['ordered ' => true ]);
206215
207216 for ($ i = 1 ; $ i <= $ n ; $ i ++) {
208217 $ bulkWrite ->insert ([
@@ -215,4 +224,4 @@ private function createFixtures($n)
215224
216225 $ this ->assertEquals ($ n , $ result ->getInsertedCount ());
217226 }
218- }
227+ }
0 commit comments