Skip to content

Commit 6afb08f

Browse files
committed
Create collection before change stream tests
1 parent a032bb3 commit 6afb08f

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

tests/DocumentationExamplesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ public function testChangeStreamExample_1_4()
930930

931931
$db = new Database($this->manager, $this->getDatabaseName());
932932
$db->dropCollection('inventory');
933+
$db->createCollection('inventory');
933934

934935
// Start Changestream Example 1
935936
$changeStream = $db->inventory->watch();

tests/Operation/WatchFunctionalTest.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,45 @@ public function setUp()
2929
parent::setUp();
3030

3131
$this->skipIfChangeStreamIsNotSupported();
32+
$this->createCollection();
3233
}
3334

3435
public function testNextResumesAfterCursorNotFound()
3536
{
36-
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
37-
3837
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
3938
$changeStream = $operation->execute($this->getPrimaryServer());
4039

4140
$changeStream->rewind();
4241
$this->assertFalse($changeStream->valid());
4342

44-
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
43+
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
4544

4645
$changeStream->next();
4746
$this->assertTrue($changeStream->valid());
4847

4948
$expectedResult = [
5049
'_id' => $changeStream->current()->_id,
5150
'operationType' => 'insert',
52-
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
51+
'fullDocument' => ['_id' => 1, 'x' => 'foo'],
5352
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
54-
'documentKey' => ['_id' => 2],
53+
'documentKey' => ['_id' => 1],
5554
];
5655

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

5958
$this->killChangeStreamCursor($changeStream);
6059

61-
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
60+
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
6261

6362
$changeStream->next();
6463
$this->assertTrue($changeStream->valid());
6564

6665
$expectedResult = [
6766
'_id' => $changeStream->current()->_id,
6867
'operationType' => 'insert',
69-
'fullDocument' => ['_id' => 3, 'x' => 'baz'],
68+
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
7069
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
71-
'documentKey' => ['_id' => 3]
70+
'documentKey' => ['_id' => 2]
7271
];
7372

7473
$this->assertMatchesDocument($expectedResult, $changeStream->current());
@@ -335,25 +334,23 @@ public function testRewindMultipleTimesWithNoResults()
335334

336335
public function testNoChangeAfterResumeBeforeInsert()
337336
{
338-
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
339-
340337
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
341338
$changeStream = $operation->execute($this->getPrimaryServer());
342339

343340
$this->assertNoCommandExecuted(function() use ($changeStream) { $changeStream->rewind(); });
344341
$this->assertFalse($changeStream->valid());
345342

346-
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
343+
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
347344

348345
$changeStream->next();
349346
$this->assertTrue($changeStream->valid());
350347

351348
$expectedResult = [
352349
'_id' => $changeStream->current()->_id,
353350
'operationType' => 'insert',
354-
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
351+
'fullDocument' => ['_id' => 1, 'x' => 'foo'],
355352
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
356-
'documentKey' => ['_id' => 2],
353+
'documentKey' => ['_id' => 1],
357354
];
358355

359356
$this->assertMatchesDocument($expectedResult, $changeStream->current());
@@ -363,27 +360,24 @@ public function testNoChangeAfterResumeBeforeInsert()
363360
$changeStream->next();
364361
$this->assertFalse($changeStream->valid());
365362

366-
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
363+
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
367364

368365
$changeStream->next();
369366
$this->assertTrue($changeStream->valid());
370367

371368
$expectedResult = [
372369
'_id' => $changeStream->current()->_id,
373370
'operationType' => 'insert',
374-
'fullDocument' => ['_id' => 3, 'x' => 'baz'],
371+
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
375372
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
376-
'documentKey' => ['_id' => 3],
373+
'documentKey' => ['_id' => 2],
377374
];
378375

379376
$this->assertMatchesDocument($expectedResult, $changeStream->current());
380377
}
381378

382379
public function testResumeMultipleTimesInSuccession()
383380
{
384-
$operation = new CreateCollection($this->getDatabaseName(), $this->getCollectionName());
385-
$operation->execute($this->getPrimaryServer());
386-
387381
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
388382
$changeStream = $operation->execute($this->getPrimaryServer());
389383

@@ -966,9 +960,6 @@ function (array $event) use (&$sessionAfterResume, &$commands) {
966960

967961
public function testSessionFreed()
968962
{
969-
// Create collection so we can drop it later
970-
$this->createCollection();
971-
972963
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
973964
$changeStream = $operation->execute($this->getPrimaryServer());
974965

0 commit comments

Comments
 (0)