Skip to content

Commit 73d2e8b

Browse files
committed
Assert change stream validity after calling next()
1 parent 003e5eb commit 73d2e8b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/Operation/WatchFunctionalTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testResume()
4242
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
4343

4444
$changeStream->next();
45+
$this->assertTrue($changeStream->valid());
4546

4647
$expectedResult = [
4748
'_id' => $changeStream->current()->_id,
@@ -58,6 +59,7 @@ public function testResume()
5859
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
5960

6061
$changeStream->next();
62+
$this->assertTrue($changeStream->valid());
6163

6264
$expectedResult = [
6365
'_id' => $changeStream->current()->_id,
@@ -139,6 +141,7 @@ public function testNoChangeAfterResumeBeforeInsert()
139141
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
140142

141143
$changeStream->next();
144+
$this->assertTrue($changeStream->valid());
142145

143146
$expectedResult = [
144147
'_id' => $changeStream->current()->_id,
@@ -153,11 +156,13 @@ public function testNoChangeAfterResumeBeforeInsert()
153156
$this->killChangeStreamCursor($changeStream);
154157

155158
$changeStream->next();
159+
$this->assertFalse($changeStream->valid());
156160
$this->assertNull($changeStream->current());
157161

158162
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
159163

160164
$changeStream->next();
165+
$this->assertTrue($changeStream->valid());
161166

162167
$expectedResult = [
163168
'_id' => $changeStream->current()->_id,
@@ -178,6 +183,7 @@ public function testResumeAfterKillThenNoOperations()
178183
$this->killChangeStreamCursor($changeStream);
179184

180185
$changeStream->next();
186+
$this->assertFalse($changeStream->valid());
181187
$this->assertNull($changeStream->current());
182188
}
183189

@@ -191,6 +197,7 @@ public function testResumeAfterKillThenOperation()
191197
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
192198

193199
$changeStream->next();
200+
$this->assertFalse($changeStream->valid());
194201
$this->assertNull($changeStream->current());
195202
}
196203

@@ -204,21 +211,27 @@ public function testKey()
204211
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
205212

206213
$changeStream->next();
214+
$this->assertTrue($changeStream->valid());
207215
$this->assertSame(1, $changeStream->key());
208216

209217
$changeStream->next();
218+
$this->assertFalse($changeStream->valid());
210219
$this->assertNull($changeStream->key());
220+
211221
$changeStream->next();
222+
$this->assertFalse($changeStream->valid());
212223
$this->assertNull($changeStream->key());
213224

214225
$this->killChangeStreamCursor($changeStream);
215226

216227
$changeStream->next();
228+
$this->assertFalse($changeStream->valid());
217229
$this->assertNull($changeStream->key());
218230

219231
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
220232

221233
$changeStream->next();
234+
$this->assertTrue($changeStream->valid());
222235
$this->assertSame(2, $changeStream->key());
223236
}
224237

@@ -232,6 +245,7 @@ public function testNonEmptyPipeline()
232245
$this->insertDocument(['_id' => 1]);
233246

234247
$changeStream->next();
248+
$this->assertTrue($changeStream->valid());
235249

236250
$expectedResult = [
237251
'_id' => $changeStream->current()->_id,

0 commit comments

Comments
 (0)