@@ -24,40 +24,40 @@ public function testResume()
24
24
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
25
25
$ this ->assertSame (1 , $ result ->getInsertedCount ());
26
26
27
- $ changeStreamResult = $ this ->collection ->watch ();
28
- $ changeStreamResult ->rewind ();
29
- $ this ->assertNull ($ changeStreamResult ->current ());
27
+ $ changeStream = $ this ->collection ->watch ();
28
+ $ changeStream ->rewind ();
29
+ $ this ->assertNull ($ changeStream ->current ());
30
30
31
31
$ result = $ this ->collection ->insertOne (['x ' => 2 ]);
32
32
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
33
33
$ this ->assertSame (1 , $ result ->getInsertedCount ());
34
34
35
- $ changeStreamResult ->next ();
35
+ $ changeStream ->next ();
36
36
$ expectedResult = (object ) ([
37
- '_id ' => $ changeStreamResult ->current ()->_id ,
37
+ '_id ' => $ changeStream ->current ()->_id ,
38
38
'operationType ' => 'insert ' ,
39
39
'fullDocument ' => (object ) ['_id ' => $ result ->getInsertedId (), 'x ' => 2 ],
40
40
'ns ' => (object ) ['db ' => 'phplib_test ' , 'coll ' => 'WatchFunctionalTest.e68b9f01 ' ],
41
41
'documentKey ' => (object ) ['_id ' => $ result ->getInsertedId ()]
42
42
]);
43
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
43
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
44
44
45
- $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStreamResult ->getCursorId ()]]);
45
+ $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStream ->getCursorId ()]]);
46
46
$ operation ->execute ($ this ->getPrimaryServer ());
47
47
48
48
$ result = $ this ->collection ->insertOne (['x ' => 3 ]);
49
49
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
50
50
$ this ->assertSame (1 , $ result ->getInsertedCount ());
51
51
52
- $ changeStreamResult ->next ();
52
+ $ changeStream ->next ();
53
53
$ expectedResult = (object ) ([
54
- '_id ' => $ changeStreamResult ->current ()->_id ,
54
+ '_id ' => $ changeStream ->current ()->_id ,
55
55
'operationType ' => 'insert ' ,
56
56
'fullDocument ' => (object ) ['_id ' => $ result ->getInsertedId (), 'x ' => 3 ],
57
57
'ns ' => (object ) ['db ' => 'phplib_test ' , 'coll ' => 'WatchFunctionalTest.e68b9f01 ' ],
58
58
'documentKey ' => (object ) ['_id ' => $ result ->getInsertedId ()]
59
59
]);
60
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
60
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
61
61
}
62
62
63
63
public function testNoChangeAfterResumeBeforeInsert ()
@@ -68,134 +68,134 @@ public function testNoChangeAfterResumeBeforeInsert()
68
68
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
69
69
$ this ->assertSame (1 , $ result ->getInsertedCount ());
70
70
71
- $ changeStreamResult = $ this ->collection ->watch ();
72
- $ changeStreamResult ->rewind ();
73
- $ this ->assertNull ($ changeStreamResult ->current ());
71
+ $ changeStream = $ this ->collection ->watch ();
72
+ $ changeStream ->rewind ();
73
+ $ this ->assertNull ($ changeStream ->current ());
74
74
75
75
$ result = $ this ->collection ->insertOne (['x ' => 2 ]);
76
76
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
77
77
$ this ->assertSame (1 , $ result ->getInsertedCount ());
78
78
79
- $ changeStreamResult ->next ();
79
+ $ changeStream ->next ();
80
80
$ expectedResult = (object ) ([
81
- '_id ' => $ changeStreamResult ->current ()->_id ,
81
+ '_id ' => $ changeStream ->current ()->_id ,
82
82
'operationType ' => 'insert ' ,
83
83
'fullDocument ' => (object ) ['_id ' => $ result ->getInsertedId (), 'x ' => 2 ],
84
84
'ns ' => (object ) ['db ' => 'phplib_test ' , 'coll ' => 'WatchFunctionalTest.4a554985 ' ],
85
85
'documentKey ' => (object ) ['_id ' => $ result ->getInsertedId ()]
86
86
]);
87
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
87
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
88
88
89
- $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStreamResult ->getCursorId ()]]);
89
+ $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStream ->getCursorId ()]]);
90
90
$ operation ->execute ($ this ->getPrimaryServer ());
91
91
92
- $ changeStreamResult ->next ();
93
- $ this ->assertNull ($ changeStreamResult ->current ());
92
+ $ changeStream ->next ();
93
+ $ this ->assertNull ($ changeStream ->current ());
94
94
95
95
$ result = $ this ->collection ->insertOne (['x ' => 3 ]);
96
96
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
97
97
$ this ->assertSame (1 , $ result ->getInsertedCount ());
98
98
99
- $ changeStreamResult ->next ();
99
+ $ changeStream ->next ();
100
100
$ expectedResult = (object ) ([
101
- '_id ' => $ changeStreamResult ->current ()->_id ,
101
+ '_id ' => $ changeStream ->current ()->_id ,
102
102
'operationType ' => 'insert ' ,
103
103
'fullDocument ' => (object ) ['_id ' => $ result ->getInsertedId (), 'x ' => 3 ],
104
104
'ns ' => (object ) ['db ' => 'phplib_test ' , 'coll ' => 'WatchFunctionalTest.4a554985 ' ],
105
105
'documentKey ' => (object ) ['_id ' => $ result ->getInsertedId ()]
106
106
]);
107
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
107
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
108
108
}
109
109
110
110
public function testResumeAfterKillThenNoOperations ()
111
111
{
112
112
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
113
113
114
- $ changeStreamResult = $ this ->collection ->watch ();
114
+ $ changeStream = $ this ->collection ->watch ();
115
115
116
- $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStreamResult ->getCursorId ()]]);
116
+ $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStream ->getCursorId ()]]);
117
117
$ operation ->execute ($ this ->getPrimaryServer ());
118
118
119
- $ changeStreamResult ->next ();
120
- $ this ->assertNull ($ changeStreamResult ->current ());
119
+ $ changeStream ->next ();
120
+ $ this ->assertNull ($ changeStream ->current ());
121
121
}
122
122
123
123
public function testResumeAfterKillThenOperation ()
124
124
{
125
125
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
126
126
127
- $ changeStreamResult = $ this ->collection ->watch ();
127
+ $ changeStream = $ this ->collection ->watch ();
128
128
129
- $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStreamResult ->getCursorId ()]]);
129
+ $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStream ->getCursorId ()]]);
130
130
$ operation ->execute ($ this ->getPrimaryServer ());
131
131
132
132
$ result = $ this ->collection ->insertOne (['x ' => 3 ]);
133
133
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
134
134
$ this ->assertSame (1 , $ result ->getInsertedCount ());
135
135
136
- $ changeStreamResult ->next ();
137
- $ this ->assertNull ($ changeStreamResult ->current ());
136
+ $ changeStream ->next ();
137
+ $ this ->assertNull ($ changeStream ->current ());
138
138
}
139
139
140
140
public function testKey ()
141
141
{
142
142
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
143
143
144
- $ changeStreamResult = $ this ->collection ->watch ();
144
+ $ changeStream = $ this ->collection ->watch ();
145
145
146
- $ this ->assertNull ($ changeStreamResult ->key ());
146
+ $ this ->assertNull ($ changeStream ->key ());
147
147
148
148
$ result = $ this ->collection ->insertOne (['x ' => 1 ]);
149
149
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
150
150
$ this ->assertSame (1 , $ result ->getInsertedCount ());
151
151
152
- $ changeStreamResult ->next ();
153
- $ this ->assertSame (1 , $ changeStreamResult ->key ());
152
+ $ changeStream ->next ();
153
+ $ this ->assertSame (1 , $ changeStream ->key ());
154
154
155
- $ changeStreamResult ->next ();
156
- $ this ->assertNull ($ changeStreamResult ->key ());
157
- $ changeStreamResult ->next ();
158
- $ this ->assertNull ($ changeStreamResult ->key ());
155
+ $ changeStream ->next ();
156
+ $ this ->assertNull ($ changeStream ->key ());
157
+ $ changeStream ->next ();
158
+ $ this ->assertNull ($ changeStream ->key ());
159
159
160
- $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStreamResult ->getCursorId ()]]);
160
+ $ operation = new DatabaseCommand ($ this ->getDatabaseName (), ["killCursors " => $ this ->getCollectionName (), "cursors " => [$ changeStream ->getCursorId ()]]);
161
161
$ operation ->execute ($ this ->getPrimaryServer ());
162
162
163
- $ changeStreamResult ->next ();
164
- $ this ->assertNull ($ changeStreamResult ->key ());
163
+ $ changeStream ->next ();
164
+ $ this ->assertNull ($ changeStream ->key ());
165
165
166
166
$ result = $ this ->collection ->insertOne (['x ' => 2 ]);
167
167
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
168
168
$ this ->assertSame (1 , $ result ->getInsertedCount ());
169
169
170
- $ changeStreamResult ->next ();
171
- $ this ->assertSame (2 , $ changeStreamResult ->key ());
170
+ $ changeStream ->next ();
171
+ $ this ->assertSame (2 , $ changeStream ->key ());
172
172
}
173
173
174
174
public function testNonEmptyPipeline ()
175
175
{
176
176
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
177
177
178
178
$ pipeline = [['$project ' => ['foo ' => [0 ]]]];
179
- $ changeStreamResult = $ this ->collection ->watch ($ pipeline , []);
179
+ $ changeStream = $ this ->collection ->watch ($ pipeline , []);
180
180
181
181
$ result = $ this ->collection ->insertOne (['x ' => 1 ]);
182
182
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
183
183
$ this ->assertSame (1 , $ result ->getInsertedCount ());
184
184
185
- $ changeStreamResult ->next ();
185
+ $ changeStream ->next ();
186
186
$ expectedResult = (object ) ([
187
- '_id ' => $ changeStreamResult ->current ()->_id ,
187
+ '_id ' => $ changeStream ->current ()->_id ,
188
188
'foo ' => [0 ]
189
189
]);
190
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
190
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
191
191
}
192
192
193
193
public function testCursorWithEmptyBatchNotClosed ()
194
194
{
195
195
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
196
196
197
- $ changeStreamResult = $ this ->collection ->watch ();
198
- $ this ->assertNotNull ($ changeStreamResult );
197
+ $ changeStream = $ this ->collection ->watch ();
198
+ $ this ->assertNotNull ($ changeStream );
199
199
}
200
200
201
201
/**
@@ -206,36 +206,36 @@ public function testFailureAfterResumeTokenRemoved()
206
206
$ this ->collection = new Collection ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName ());
207
207
208
208
$ pipeline = [['$project ' => ['_id ' => 0 ]]];
209
- $ changeStreamResult = $ this ->collection ->watch ($ pipeline , []);
209
+ $ changeStream = $ this ->collection ->watch ($ pipeline , []);
210
210
211
211
$ result = $ this ->collection ->insertOne (['x ' => 1 ]);
212
212
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
213
213
$ this ->assertSame (1 , $ result ->getInsertedCount ());
214
214
215
- $ changeStreamResult ->next ();
215
+ $ changeStream ->next ();
216
216
}
217
217
218
218
public function testConnectionException ()
219
219
{
220
220
$ client = new Client ($ this ->getUri (), ['socketTimeoutMS ' => 1005 ], []);
221
221
$ collection = $ client ->selectCollection ($ this ->getDatabaseName (), $ this ->getCollectionName ());
222
222
223
- $ changeStreamResult = $ collection ->watch ();
224
- $ changeStreamResult ->next ();
223
+ $ changeStream = $ collection ->watch ();
224
+ $ changeStream ->next ();
225
225
226
226
$ result = $ collection ->insertOne (['x ' => 1 ]);
227
227
$ this ->assertInstanceOf ('MongoDB\InsertOneResult ' , $ result );
228
228
$ this ->assertSame (1 , $ result ->getInsertedCount ());
229
229
230
- $ changeStreamResult ->next ();
230
+ $ changeStream ->next ();
231
231
$ expectedResult = (object ) ([
232
- '_id ' => $ changeStreamResult ->current ()->_id ,
232
+ '_id ' => $ changeStream ->current ()->_id ,
233
233
'operationType ' => 'insert ' ,
234
234
'fullDocument ' => (object ) ['_id ' => $ result ->getInsertedId (), 'x ' => 1 ],
235
235
'ns ' => (object ) ['db ' => 'phplib_test ' , 'coll ' => 'WatchFunctionalTest.226d95f1 ' ],
236
236
'documentKey ' => (object ) ['_id ' => $ result ->getInsertedId ()]
237
237
]);
238
- $ this ->assertEquals ($ changeStreamResult ->current (), $ expectedResult );
238
+ $ this ->assertEquals ($ changeStream ->current (), $ expectedResult );
239
239
}
240
240
241
241
public function testMaxAwaitTimeMS ()
@@ -245,30 +245,30 @@ public function testMaxAwaitTimeMS()
245
245
* change stream on the server so we'll use a higher maxAwaitTimeMS to
246
246
* ensure we see the write. */
247
247
$ maxAwaitTimeMS = 100 ;
248
- $ changeStreamResult = $ this ->collection ->watch ([], ['maxAwaitTimeMS ' => $ maxAwaitTimeMS ]);
248
+ $ changeStream = $ this ->collection ->watch ([], ['maxAwaitTimeMS ' => $ maxAwaitTimeMS ]);
249
249
250
250
/* The initial change stream is empty so we should expect a delay when
251
251
* we call rewind, since it issues a getMore. Expect to wait at least
252
252
* maxAwaitTimeMS, since no new documents should be inserted to wake up
253
253
* the server's query thread. Also ensure we don't wait too long (server
254
254
* default is one second). */
255
255
$ startTime = microtime (true );
256
- $ changeStreamResult ->rewind ();
256
+ $ changeStream ->rewind ();
257
257
$ duration = microtime (true ) - $ startTime ;
258
258
$ this ->assertGreaterThanOrEqual ($ maxAwaitTimeMS * 0.001 , $ duration );
259
259
$ this ->assertLessThan (0.5 , $ duration );
260
260
261
- $ this ->assertFalse ($ changeStreamResult ->valid ());
261
+ $ this ->assertFalse ($ changeStream ->valid ());
262
262
263
263
/* Advancing again on a change stream will issue a getMore, so we should
264
264
* expect a delay again. */
265
265
$ startTime = microtime (true );
266
- $ changeStreamResult ->next ();
266
+ $ changeStream ->next ();
267
267
$ duration = microtime (true ) - $ startTime ;
268
268
$ this ->assertGreaterThanOrEqual ($ maxAwaitTimeMS * 0.001 , $ duration );
269
269
$ this ->assertLessThan (0.5 , $ duration );
270
270
271
- $ this ->assertFalse ($ changeStreamResult ->valid ());
271
+ $ this ->assertFalse ($ changeStream ->valid ());
272
272
273
273
/* After inserting a document, the change stream will not issue a
274
274
* getMore so we should not expect a delay. */
@@ -277,9 +277,9 @@ public function testMaxAwaitTimeMS()
277
277
$ this ->assertSame (1 , $ result ->getInsertedCount ());
278
278
279
279
$ startTime = microtime (true );
280
- $ changeStreamResult ->next ();
280
+ $ changeStream ->next ();
281
281
$ duration = microtime (true ) - $ startTime ;
282
282
$ this ->assertLessThan ($ maxAwaitTimeMS * 0.001 , $ duration );
283
- $ this ->assertTrue ($ changeStreamResult ->valid ());
283
+ $ this ->assertTrue ($ changeStream ->valid ());
284
284
}
285
285
}
0 commit comments