Unverified Commit 60e3ca24 authored by Katherine Walker's avatar Katherine Walker Committed by GitHub

[WAIT] PHPLIB-289 ChangeStreams Examples for Docs (#436)

* PHPLIB-289 ChangeStreams Examples for Docs
parent 0aedcbaf
......@@ -925,6 +925,60 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertInventoryCount(0);
}
public function testChangeStreamExample_1_3()
{
$db = new Database($this->manager, $this->getDatabaseName());
// Start Changestream Example 1
$cursor = $db->inventory->watch();
$cursor->next();
$current = $cursor->current();
// End Changestream Example 1
$this->assertNull($current);
// Start Changestream Example 2
$cursor = $db->inventory->watch([], ['fullDocument' => \MongoDB\Operation\ChangeStreamCommand::FULL_DOCUMENT_UPDATE_LOOKUP]);
$cursor->next();
$current = $cursor->current();
// End Changestream Example 2
$this->assertNull($current);
$insertedResult = $db->inventory->insertOne(['x' => 1]);
$insertedId = $insertedResult->getInsertedId();
$cursor->next();
$current = $cursor->current();
$expectedChange = (object) [
'_id' => $current->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 1],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId]
];
$this->assertEquals($current, $expectedChange);
// Start Changestream Example 3
$resumeToken = ($current !== null) ? $current->_id : null;
if ($resumeToken !== null) {
$cursor = $db->inventory->watch([], ['resumeAfter' => $resumeToken]);
$cursor->next();
}
// End Changestream Example 3
$insertedResult = $db->inventory->insertOne(['x' => 2]);
$insertedId = $insertedResult->getInsertedId();
$cursor->next();
$expectedChange = (object) [
'_id' => $cursor->current()->_id,
'operationType' => 'insert',
'fullDocument' => (object) ['_id' => $insertedId, 'x' => 2],
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'inventory'],
'documentKey' => (object) ['_id' => $insertedId]
];
$this->assertEquals($cursor->current(), $expectedChange);
}
/**
* Return the test collection name.
*
......
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