@@ -402,20 +402,29 @@ public function testResumeMultipleTimesInSuccession()
402
402
403
403
$ this ->insertDocument (['_id ' => 1 ]);
404
404
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
+
405
414
/* Killing the cursor and advancing when there is a result will test
406
415
* that next()'s resume attempt picks up the latest change. */
407
416
$ this ->killChangeStreamCursor ($ changeStream );
408
417
409
418
$ changeStream ->next ();
410
419
$ this ->assertTrue ($ changeStream ->valid ());
411
- $ this ->assertSame (0 , $ changeStream ->key ());
420
+ $ this ->assertSame (1 , $ changeStream ->key ());
412
421
413
422
$ expectedResult = [
414
423
'_id ' => $ changeStream ->current ()->_id ,
415
424
'operationType ' => 'insert ' ,
416
- 'fullDocument ' => ['_id ' => 1 ],
425
+ 'fullDocument ' => ['_id ' => 2 ],
417
426
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
418
- 'documentKey ' => ['_id ' => 1 ],
427
+ 'documentKey ' => ['_id ' => 2 ],
419
428
];
420
429
421
430
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
@@ -428,48 +437,48 @@ public function testResumeMultipleTimesInSuccession()
428
437
429
438
$ changeStream ->rewind ();
430
439
$ this ->assertTrue ($ changeStream ->valid ());
431
- $ this ->assertSame (0 , $ changeStream ->key ());
440
+ $ this ->assertSame (1 , $ changeStream ->key ());
432
441
433
442
$ expectedResult = [
434
443
'_id ' => $ changeStream ->current ()->_id ,
435
444
'operationType ' => 'insert ' ,
436
- 'fullDocument ' => ['_id ' => 1 ],
445
+ 'fullDocument ' => ['_id ' => 2 ],
437
446
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
438
- 'documentKey ' => ['_id ' => 1 ],
447
+ 'documentKey ' => ['_id ' => 2 ],
439
448
];
440
449
441
450
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
442
451
443
- $ this ->insertDocument (['_id ' => 2 ]);
452
+ $ this ->insertDocument (['_id ' => 3 ]);
444
453
445
454
$ changeStream ->next ();
446
455
$ this ->assertTrue ($ changeStream ->valid ());
447
- $ this ->assertSame (1 , $ changeStream ->key ());
456
+ $ this ->assertSame (2 , $ changeStream ->key ());
448
457
449
458
$ expectedResult = [
450
459
'_id ' => $ changeStream ->current ()->_id ,
451
460
'operationType ' => 'insert ' ,
452
- 'fullDocument ' => ['_id ' => 2 ],
461
+ 'fullDocument ' => ['_id ' => 3 ],
453
462
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
454
- 'documentKey ' => ['_id ' => 2 ],
463
+ 'documentKey ' => ['_id ' => 3 ],
455
464
];
456
465
457
466
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
458
467
459
468
$ this ->killChangeStreamCursor ($ changeStream );
460
469
461
- $ this ->insertDocument (['_id ' => 3 ]);
470
+ $ this ->insertDocument (['_id ' => 4 ]);
462
471
463
472
$ changeStream ->next ();
464
473
$ this ->assertTrue ($ changeStream ->valid ());
465
- $ this ->assertSame (2 , $ changeStream ->key ());
474
+ $ this ->assertSame (3 , $ changeStream ->key ());
466
475
467
476
$ expectedResult = [
468
477
'_id ' => $ changeStream ->current ()->_id ,
469
478
'operationType ' => 'insert ' ,
470
- 'fullDocument ' => ['_id ' => 3 ],
479
+ 'fullDocument ' => ['_id ' => 4 ],
471
480
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
472
- 'documentKey ' => ['_id ' => 3 ],
481
+ 'documentKey ' => ['_id ' => 4 ],
473
482
];
474
483
475
484
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
@@ -480,18 +489,18 @@ public function testResumeMultipleTimesInSuccession()
480
489
* we'll see {_id: 3} returned again. */
481
490
$ this ->killChangeStreamCursor ($ changeStream );
482
491
483
- $ this ->insertDocument (['_id ' => 4 ]);
492
+ $ this ->insertDocument (['_id ' => 5 ]);
484
493
485
494
$ changeStream ->next ();
486
495
$ this ->assertTrue ($ changeStream ->valid ());
487
- $ this ->assertSame (3 , $ changeStream ->key ());
496
+ $ this ->assertSame (4 , $ changeStream ->key ());
488
497
489
498
$ expectedResult = [
490
499
'_id ' => $ changeStream ->current ()->_id ,
491
500
'operationType ' => 'insert ' ,
492
- 'fullDocument ' => ['_id ' => 4 ],
501
+ 'fullDocument ' => ['_id ' => 5 ],
493
502
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
494
- 'documentKey ' => ['_id ' => 4 ],
503
+ 'documentKey ' => ['_id ' => 5 ],
495
504
];
496
505
497
506
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
0 commit comments