Skip to content

Commit 8e88c5c

Browse files
committed
PHPLIB-454: Remove test dependence on startAtOperationTime
1 parent db79201 commit 8e88c5c

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

tests/Operation/WatchFunctionalTest.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -402,20 +402,29 @@ public function testResumeMultipleTimesInSuccession()
402402

403403
$this->insertDocument(['_id' => 1]);
404404

405+
/* Insert a document and advance the change stream to ensure we capture
406+
* a resume token. This is necessary when startAtOperationTime is not
407+
* supported (i.e. 3.6 server version). */
408+
$changeStream->next();
409+
$this->assertTrue($changeStream->valid());
410+
$this->assertSame(0, $changeStream->key());
411+
412+
$this->insertDocument(['_id' => 2]);
413+
405414
/* Killing the cursor and advancing when there is a result will test
406415
* that next()'s resume attempt picks up the latest change. */
407416
$this->killChangeStreamCursor($changeStream);
408417

409418
$changeStream->next();
410419
$this->assertTrue($changeStream->valid());
411-
$this->assertSame(0, $changeStream->key());
420+
$this->assertSame(1, $changeStream->key());
412421

413422
$expectedResult = [
414423
'_id' => $changeStream->current()->_id,
415424
'operationType' => 'insert',
416-
'fullDocument' => ['_id' => 1],
425+
'fullDocument' => ['_id' => 2],
417426
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
418-
'documentKey' => ['_id' => 1],
427+
'documentKey' => ['_id' => 2],
419428
];
420429

421430
$this->assertMatchesDocument($expectedResult, $changeStream->current());
@@ -428,48 +437,48 @@ public function testResumeMultipleTimesInSuccession()
428437

429438
$changeStream->rewind();
430439
$this->assertTrue($changeStream->valid());
431-
$this->assertSame(0, $changeStream->key());
440+
$this->assertSame(1, $changeStream->key());
432441

433442
$expectedResult = [
434443
'_id' => $changeStream->current()->_id,
435444
'operationType' => 'insert',
436-
'fullDocument' => ['_id' => 1],
445+
'fullDocument' => ['_id' => 2],
437446
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
438-
'documentKey' => ['_id' => 1],
447+
'documentKey' => ['_id' => 2],
439448
];
440449

441450
$this->assertMatchesDocument($expectedResult, $changeStream->current());
442451

443-
$this->insertDocument(['_id' => 2]);
452+
$this->insertDocument(['_id' => 3]);
444453

445454
$changeStream->next();
446455
$this->assertTrue($changeStream->valid());
447-
$this->assertSame(1, $changeStream->key());
456+
$this->assertSame(2, $changeStream->key());
448457

449458
$expectedResult = [
450459
'_id' => $changeStream->current()->_id,
451460
'operationType' => 'insert',
452-
'fullDocument' => ['_id' => 2],
461+
'fullDocument' => ['_id' => 3],
453462
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
454-
'documentKey' => ['_id' => 2],
463+
'documentKey' => ['_id' => 3],
455464
];
456465

457466
$this->assertMatchesDocument($expectedResult, $changeStream->current());
458467

459468
$this->killChangeStreamCursor($changeStream);
460469

461-
$this->insertDocument(['_id' => 3]);
470+
$this->insertDocument(['_id' => 4]);
462471

463472
$changeStream->next();
464473
$this->assertTrue($changeStream->valid());
465-
$this->assertSame(2, $changeStream->key());
474+
$this->assertSame(3, $changeStream->key());
466475

467476
$expectedResult = [
468477
'_id' => $changeStream->current()->_id,
469478
'operationType' => 'insert',
470-
'fullDocument' => ['_id' => 3],
479+
'fullDocument' => ['_id' => 4],
471480
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
472-
'documentKey' => ['_id' => 3],
481+
'documentKey' => ['_id' => 4],
473482
];
474483

475484
$this->assertMatchesDocument($expectedResult, $changeStream->current());
@@ -480,18 +489,18 @@ public function testResumeMultipleTimesInSuccession()
480489
* we'll see {_id: 3} returned again. */
481490
$this->killChangeStreamCursor($changeStream);
482491

483-
$this->insertDocument(['_id' => 4]);
492+
$this->insertDocument(['_id' => 5]);
484493

485494
$changeStream->next();
486495
$this->assertTrue($changeStream->valid());
487-
$this->assertSame(3, $changeStream->key());
496+
$this->assertSame(4, $changeStream->key());
488497

489498
$expectedResult = [
490499
'_id' => $changeStream->current()->_id,
491500
'operationType' => 'insert',
492-
'fullDocument' => ['_id' => 4],
501+
'fullDocument' => ['_id' => 5],
493502
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
494-
'documentKey' => ['_id' => 4],
503+
'documentKey' => ['_id' => 5],
495504
];
496505

497506
$this->assertMatchesDocument($expectedResult, $changeStream->current());

0 commit comments

Comments
 (0)