@@ -29,46 +29,45 @@ public function setUp()
29
29
parent ::setUp ();
30
30
31
31
$ this ->skipIfChangeStreamIsNotSupported ();
32
+ $ this ->createCollection ();
32
33
}
33
34
34
35
public function testNextResumesAfterCursorNotFound ()
35
36
{
36
- $ this ->insertDocument (['_id ' => 1 , 'x ' => 'foo ' ]);
37
-
38
37
$ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
39
38
$ changeStream = $ operation ->execute ($ this ->getPrimaryServer ());
40
39
41
40
$ changeStream ->rewind ();
42
41
$ this ->assertFalse ($ changeStream ->valid ());
43
42
44
- $ this ->insertDocument (['_id ' => 2 , 'x ' => 'bar ' ]);
43
+ $ this ->insertDocument (['_id ' => 1 , 'x ' => 'foo ' ]);
45
44
46
45
$ changeStream ->next ();
47
46
$ this ->assertTrue ($ changeStream ->valid ());
48
47
49
48
$ expectedResult = [
50
49
'_id ' => $ changeStream ->current ()->_id ,
51
50
'operationType ' => 'insert ' ,
52
- 'fullDocument ' => ['_id ' => 2 , 'x ' => 'bar ' ],
51
+ 'fullDocument ' => ['_id ' => 1 , 'x ' => 'foo ' ],
53
52
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
54
- 'documentKey ' => ['_id ' => 2 ],
53
+ 'documentKey ' => ['_id ' => 1 ],
55
54
];
56
55
57
56
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
58
57
59
58
$ this ->killChangeStreamCursor ($ changeStream );
60
59
61
- $ this ->insertDocument (['_id ' => 3 , 'x ' => 'baz ' ]);
60
+ $ this ->insertDocument (['_id ' => 2 , 'x ' => 'bar ' ]);
62
61
63
62
$ changeStream ->next ();
64
63
$ this ->assertTrue ($ changeStream ->valid ());
65
64
66
65
$ expectedResult = [
67
66
'_id ' => $ changeStream ->current ()->_id ,
68
67
'operationType ' => 'insert ' ,
69
- 'fullDocument ' => ['_id ' => 3 , 'x ' => 'baz ' ],
68
+ 'fullDocument ' => ['_id ' => 2 , 'x ' => 'bar ' ],
70
69
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
71
- 'documentKey ' => ['_id ' => 3 ]
70
+ 'documentKey ' => ['_id ' => 2 ]
72
71
];
73
72
74
73
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
@@ -335,25 +334,23 @@ public function testRewindMultipleTimesWithNoResults()
335
334
336
335
public function testNoChangeAfterResumeBeforeInsert ()
337
336
{
338
- $ this ->insertDocument (['_id ' => 1 , 'x ' => 'foo ' ]);
339
-
340
337
$ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
341
338
$ changeStream = $ operation ->execute ($ this ->getPrimaryServer ());
342
339
343
340
$ this ->assertNoCommandExecuted (function () use ($ changeStream ) { $ changeStream ->rewind (); });
344
341
$ this ->assertFalse ($ changeStream ->valid ());
345
342
346
- $ this ->insertDocument (['_id ' => 2 , 'x ' => 'bar ' ]);
343
+ $ this ->insertDocument (['_id ' => 1 , 'x ' => 'foo ' ]);
347
344
348
345
$ changeStream ->next ();
349
346
$ this ->assertTrue ($ changeStream ->valid ());
350
347
351
348
$ expectedResult = [
352
349
'_id ' => $ changeStream ->current ()->_id ,
353
350
'operationType ' => 'insert ' ,
354
- 'fullDocument ' => ['_id ' => 2 , 'x ' => 'bar ' ],
351
+ 'fullDocument ' => ['_id ' => 1 , 'x ' => 'foo ' ],
355
352
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
356
- 'documentKey ' => ['_id ' => 2 ],
353
+ 'documentKey ' => ['_id ' => 1 ],
357
354
];
358
355
359
356
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
@@ -363,27 +360,24 @@ public function testNoChangeAfterResumeBeforeInsert()
363
360
$ changeStream ->next ();
364
361
$ this ->assertFalse ($ changeStream ->valid ());
365
362
366
- $ this ->insertDocument (['_id ' => 3 , 'x ' => 'baz ' ]);
363
+ $ this ->insertDocument (['_id ' => 2 , 'x ' => 'bar ' ]);
367
364
368
365
$ changeStream ->next ();
369
366
$ this ->assertTrue ($ changeStream ->valid ());
370
367
371
368
$ expectedResult = [
372
369
'_id ' => $ changeStream ->current ()->_id ,
373
370
'operationType ' => 'insert ' ,
374
- 'fullDocument ' => ['_id ' => 3 , 'x ' => 'baz ' ],
371
+ 'fullDocument ' => ['_id ' => 2 , 'x ' => 'bar ' ],
375
372
'ns ' => ['db ' => $ this ->getDatabaseName (), 'coll ' => $ this ->getCollectionName ()],
376
- 'documentKey ' => ['_id ' => 3 ],
373
+ 'documentKey ' => ['_id ' => 2 ],
377
374
];
378
375
379
376
$ this ->assertMatchesDocument ($ expectedResult , $ changeStream ->current ());
380
377
}
381
378
382
379
public function testResumeMultipleTimesInSuccession ()
383
380
{
384
- $ operation = new CreateCollection ($ this ->getDatabaseName (), $ this ->getCollectionName ());
385
- $ operation ->execute ($ this ->getPrimaryServer ());
386
-
387
381
$ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
388
382
$ changeStream = $ operation ->execute ($ this ->getPrimaryServer ());
389
383
@@ -966,9 +960,6 @@ function (array $event) use (&$sessionAfterResume, &$commands) {
966
960
967
961
public function testSessionFreed ()
968
962
{
969
- // Create collection so we can drop it later
970
- $ this ->createCollection ();
971
-
972
963
$ operation = new Watch ($ this ->manager , $ this ->getDatabaseName (), $ this ->getCollectionName (), [], $ this ->defaultOptions );
973
964
$ changeStream = $ operation ->execute ($ this ->getPrimaryServer ());
974
965
0 commit comments