Skip to content

Commit 306e568

Browse files
committed
Start iteration with rewind() in ChangeStream::key() test
Previously, iteration started with next(), so the first element's key was 1. Iteration should being with rewind() and the initial key should be zero. With this change, we're still testing that the key is only incremented when next() successfully increments.
1 parent a49d6e5 commit 306e568

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tests/Operation/WatchFunctionalTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,14 @@ public function testKey()
180180
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
181181
$changeStream = $operation->execute($this->getPrimaryServer());
182182

183+
$this->assertFalse($changeStream->valid());
183184
$this->assertNull($changeStream->key());
184185

185186
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
186187

187-
$changeStream->next();
188+
$changeStream->rewind();
188189
$this->assertTrue($changeStream->valid());
189-
$this->assertSame(1, $changeStream->key());
190+
$this->assertSame(0, $changeStream->key());
190191

191192
$changeStream->next();
192193
$this->assertFalse($changeStream->valid());
@@ -206,7 +207,7 @@ public function testKey()
206207

207208
$changeStream->next();
208209
$this->assertTrue($changeStream->valid());
209-
$this->assertSame(2, $changeStream->key());
210+
$this->assertSame(1, $changeStream->key());
210211
}
211212

212213
public function testNonEmptyPipeline()

0 commit comments

Comments
 (0)