Commit 41892d26 authored by Jeremy Mikola's avatar Jeremy Mikola

Use assertSameDocument to check change stream results

This also removes the hard-coded database and collection names, which are subject to change based on the test suite configuration and getCollectionName() implementation.
parent 3a4e9202
......@@ -954,14 +954,16 @@ class DocumentationExamplesTest extends FunctionalTestCase
$insertedId = $insertedResult->getInsertedId();
$cursor->next();
$current = $cursor->current();
$expectedChange = (object) [
$expectedChange = [
'_id' => $current->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 1],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId]
'fullDocument' => ['_id' => $insertedId, 'x' => 1],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => 'inventory'],
'documentKey' => ['_id' => $insertedId],
];
$this->assertEquals($expectedChange, $current);
$this->assertSameDocument($expectedChange, $current);
// Start Changestream Example 3
$resumeToken = ($current !== null) ? $current->_id : null;
......@@ -974,14 +976,16 @@ class DocumentationExamplesTest extends FunctionalTestCase
$insertedResult = $db->inventory->insertOne(['x' => 2]);
$insertedId = $insertedResult->getInsertedId();
$cursor->next();
$expectedChange = (object) [
$expectedChange = [
'_id' => $cursor->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 2],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId]
'fullDocument' => ['_id' => $insertedId, 'x' => 2],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => 'inventory'],
'documentKey' => ['_id' => $insertedId],
];
$this->assertEquals($expectedChange, $cursor->current());
$this->assertSameDocument($expectedChange, $cursor->current());
// Start Changestream Example 4
$pipeline = [['$match' => ['$or' => [['fullDocument.username' => 'alice'], ['operationType' => 'delete']]]]];
......
......@@ -41,14 +41,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => 2, 'x' => 'bar'],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
'documentKey' => (object) ['_id' => 2]
]);
$this->assertEquals($expectedResult, $changeStream->current());
$expectedResult = [
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 2],
];
$this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
$operation->execute($this->getPrimaryServer());
......@@ -56,14 +58,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
$changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => 3, 'x' => 'baz'],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
'documentKey' => (object) ['_id' => 3]
]);
$this->assertEquals($expectedResult, $changeStream->current());
$expectedResult = [
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => ['_id' => 3, 'x' => 'baz'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 3]
];
$this->assertSameDocument($expectedResult, $changeStream->current());
}
/**
......@@ -135,14 +139,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => 2, 'x' => 'bar'],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
'documentKey' => (object) ['_id' => 2]
]);
$this->assertEquals($expectedResult, $changeStream->current());
$expectedResult = [
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 2],
];
$this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
$operation->execute($this->getPrimaryServer());
......@@ -153,14 +159,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 3, 'x' => 'baz']);
$changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => 3, 'x' => 'baz'],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
'documentKey' => (object) ['_id' => 3]
]);
$this->assertEquals($expectedResult, $changeStream->current());
$expectedResult = [
'_id' => $changeStream->current()->_id,
'operationType' => 'insert',
'fullDocument' => ['_id' => 3, 'x' => 'baz'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 3],
];
$this->assertSameDocument($expectedResult, $changeStream->current());
}
public function testResumeAfterKillThenNoOperations()
......@@ -228,11 +236,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 1]);
$changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id,
'foo' => [0]
]);
$this->assertEquals($expectedResult, $changeStream->current());
$expectedResult = [
'_id' => $changeStream->current()->_id,
'foo' => [0],
];
$this->assertSameDocument($expectedResult, $changeStream->current());
}
public function testCursorWithEmptyBatchNotClosed()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment