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 ...@@ -954,14 +954,16 @@ class DocumentationExamplesTest extends FunctionalTestCase
$insertedId = $insertedResult->getInsertedId(); $insertedId = $insertedResult->getInsertedId();
$cursor->next(); $cursor->next();
$current = $cursor->current(); $current = $cursor->current();
$expectedChange = (object) [
$expectedChange = [
'_id' => $current->_id, '_id' => $current->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 1], 'fullDocument' => ['_id' => $insertedId, 'x' => 1],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId] 'documentKey' => ['_id' => $insertedId],
]; ];
$this->assertEquals($expectedChange, $current);
$this->assertSameDocument($expectedChange, $current);
// Start Changestream Example 3 // Start Changestream Example 3
$resumeToken = ($current !== null) ? $current->_id : null; $resumeToken = ($current !== null) ? $current->_id : null;
...@@ -974,14 +976,16 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -974,14 +976,16 @@ class DocumentationExamplesTest extends FunctionalTestCase
$insertedResult = $db->inventory->insertOne(['x' => 2]); $insertedResult = $db->inventory->insertOne(['x' => 2]);
$insertedId = $insertedResult->getInsertedId(); $insertedId = $insertedResult->getInsertedId();
$cursor->next(); $cursor->next();
$expectedChange = (object) [
$expectedChange = [
'_id' => $cursor->current()->_id, '_id' => $cursor->current()->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 2], 'fullDocument' => ['_id' => $insertedId, 'x' => 2],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId] 'documentKey' => ['_id' => $insertedId],
]; ];
$this->assertEquals($expectedChange, $cursor->current());
$this->assertSameDocument($expectedChange, $cursor->current());
// Start Changestream Example 4 // Start Changestream Example 4
$pipeline = [['$match' => ['$or' => [['fullDocument.username' => 'alice'], ['operationType' => 'delete']]]]]; $pipeline = [['$match' => ['$or' => [['fullDocument.username' => 'alice'], ['operationType' => 'delete']]]]];
......
...@@ -41,14 +41,16 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -41,14 +41,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 2, 'x' => 'bar']); $this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next(); $changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id, $expectedResult = [
'operationType' => 'insert', '_id' => $changeStream->current()->_id,
'fullDocument' => (object) ['_id' => 2, 'x' => 'bar'], 'operationType' => 'insert',
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'], 'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'documentKey' => (object) ['_id' => 2] 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
]); 'documentKey' => ['_id' => 2],
$this->assertEquals($expectedResult, $changeStream->current()); ];
$this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
$operation->execute($this->getPrimaryServer()); $operation->execute($this->getPrimaryServer());
...@@ -56,14 +58,16 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -56,14 +58,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 3, 'x' => 'baz']); $this->insertDocument(['_id' => 3, 'x' => 'baz']);
$changeStream->next(); $changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id, $expectedResult = [
'operationType' => 'insert', '_id' => $changeStream->current()->_id,
'fullDocument' => (object) ['_id' => 3, 'x' => 'baz'], 'operationType' => 'insert',
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'], 'fullDocument' => ['_id' => 3, 'x' => 'baz'],
'documentKey' => (object) ['_id' => 3] 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
]); 'documentKey' => ['_id' => 3]
$this->assertEquals($expectedResult, $changeStream->current()); ];
$this->assertSameDocument($expectedResult, $changeStream->current());
} }
/** /**
...@@ -135,14 +139,16 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -135,14 +139,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 2, 'x' => 'bar']); $this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next(); $changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id, $expectedResult = [
'operationType' => 'insert', '_id' => $changeStream->current()->_id,
'fullDocument' => (object) ['_id' => 2, 'x' => 'bar'], 'operationType' => 'insert',
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'], 'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'documentKey' => (object) ['_id' => 2] 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
]); 'documentKey' => ['_id' => 2],
$this->assertEquals($expectedResult, $changeStream->current()); ];
$this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
$operation->execute($this->getPrimaryServer()); $operation->execute($this->getPrimaryServer());
...@@ -153,14 +159,16 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -153,14 +159,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 3, 'x' => 'baz']); $this->insertDocument(['_id' => 3, 'x' => 'baz']);
$changeStream->next(); $changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id, $expectedResult = [
'operationType' => 'insert', '_id' => $changeStream->current()->_id,
'fullDocument' => (object) ['_id' => 3, 'x' => 'baz'], 'operationType' => 'insert',
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'], 'fullDocument' => ['_id' => 3, 'x' => 'baz'],
'documentKey' => (object) ['_id' => 3] 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
]); 'documentKey' => ['_id' => 3],
$this->assertEquals($expectedResult, $changeStream->current()); ];
$this->assertSameDocument($expectedResult, $changeStream->current());
} }
public function testResumeAfterKillThenNoOperations() public function testResumeAfterKillThenNoOperations()
...@@ -228,11 +236,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -228,11 +236,13 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->insertDocument(['_id' => 1]); $this->insertDocument(['_id' => 1]);
$changeStream->next(); $changeStream->next();
$expectedResult = (object) ([
'_id' => $changeStream->current()->_id, $expectedResult = [
'foo' => [0] '_id' => $changeStream->current()->_id,
]); 'foo' => [0],
$this->assertEquals($expectedResult, $changeStream->current()); ];
$this->assertSameDocument($expectedResult, $changeStream->current());
} }
public function testCursorWithEmptyBatchNotClosed() 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