2
2
3
3
namespace MongoDB \Tests \Collection ;
4
4
5
- use MongoDB \Driver \BulkWrite ;
5
+ use MongoDB \Driver \BulkWrite as Bulk ;
6
+ use MongoDB \Operation \BulkWrite ;
6
7
7
8
class BulkWriteFunctionalTest extends FunctionalTestCase
8
9
{
@@ -22,7 +23,9 @@ public function testInserts()
22
23
['insertOne ' => [['x ' => 22 ]]],
23
24
];
24
25
25
- $ result = $ this ->collection ->bulkWrite ($ ops );
26
+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
27
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
28
+
26
29
$ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
27
30
$ this ->assertSame (2 , $ result ->getInsertedCount ());
28
31
@@ -50,7 +53,9 @@ public function testUpdates()
50
53
['updateMany ' => [['x ' => ['$gt ' => 50 ]], ['$inc ' => ['x ' => 1 ]]]],
51
54
];
52
55
53
- $ result = $ this ->collection ->bulkWrite ($ ops );
56
+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
57
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
58
+
54
59
$ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
55
60
$ this ->assertSame (5 , $ result ->getMatchedCount ());
56
61
$ this ->omitModifiedCount or $ this ->assertSame (5 , $ result ->getModifiedCount ());
@@ -81,7 +86,9 @@ public function testDeletes()
81
86
['deleteMany ' => [['_id ' => ['$gt ' => 2 ]]]],
82
87
];
83
88
84
- $ result = $ this ->collection ->bulkWrite ($ ops );
89
+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
90
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
91
+
85
92
$ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
86
93
$ this ->assertSame (3 , $ result ->getDeletedCount ());
87
94
@@ -104,7 +111,9 @@ public function testMixedOrderedOperations()
104
111
['replaceOne ' => [['_id ' => 4 ], ['_id ' => 4 , 'x ' => 44 ], ['upsert ' => true ]]],
105
112
];
106
113
107
- $ result = $ this ->collection ->bulkWrite ($ ops );
114
+ $ operation = new BulkWrite ($ this ->getDatabaseName (), $ this ->getCollectionName (), $ ops );
115
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
116
+
108
117
$ this ->assertInstanceOf ('MongoDB\BulkWriteResult ' , $ result );
109
118
110
119
$ this ->assertSame (1 , $ result ->getInsertedCount ());
@@ -132,7 +141,7 @@ public function testMixedOrderedOperations()
132
141
*/
133
142
public function testUnknownOperation ()
134
143
{
135
- $ this ->collection -> bulkWrite ( [
144
+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
136
145
['foo ' => [['_id ' => 1 ]]],
137
146
]);
138
147
}
@@ -144,7 +153,7 @@ public function testUnknownOperation()
144
153
*/
145
154
public function testMissingArguments (array $ ops )
146
155
{
147
- $ this ->collection -> bulkWrite ( $ ops );
156
+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), $ ops );
148
157
}
149
158
150
159
public function provideOpsWithMissingArguments ()
@@ -168,7 +177,7 @@ public function provideOpsWithMissingArguments()
168
177
*/
169
178
public function testUpdateOneRequiresUpdateOperators ()
170
179
{
171
- $ this ->collection -> bulkWrite ( [
180
+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
172
181
['updateOne ' => [['_id ' => 1 ], ['x ' => 1 ]]],
173
182
]);
174
183
}
@@ -179,7 +188,7 @@ public function testUpdateOneRequiresUpdateOperators()
179
188
*/
180
189
public function testUpdateManyRequiresUpdateOperators ()
181
190
{
182
- $ this ->collection -> bulkWrite ( [
191
+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
183
192
['updateMany ' => [['_id ' => ['$gt ' => 1 ]], ['x ' => 1 ]]],
184
193
]);
185
194
}
@@ -190,7 +199,7 @@ public function testUpdateManyRequiresUpdateOperators()
190
199
*/
191
200
public function testReplaceOneRequiresReplacementDocument ()
192
201
{
193
- $ this ->collection -> bulkWrite ( [
202
+ new BulkWrite ( $ this ->getDatabaseName (), $ this -> getCollectionName (), [
194
203
['replaceOne ' => [['_id ' => 1 ], ['$inc ' => ['x ' => 1 ]]]],
195
204
]);
196
205
}
@@ -202,7 +211,7 @@ public function testReplaceOneRequiresReplacementDocument()
202
211
*/
203
212
private function createFixtures ($ n )
204
213
{
205
- $ bulkWrite = new BulkWrite (['ordered ' => true ]);
214
+ $ bulkWrite = new Bulk (['ordered ' => true ]);
206
215
207
216
for ($ i = 1 ; $ i <= $ n ; $ i ++) {
208
217
$ bulkWrite ->insert ([
@@ -215,4 +224,4 @@ private function createFixtures($n)
215
224
216
225
$ this ->assertEquals ($ n , $ result ->getInsertedCount ());
217
226
}
218
- }
227
+ }
0 commit comments