Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
60e3ca24
Unverified
Commit
60e3ca24
authored
Nov 29, 2017
by
Katherine Walker
Committed by
GitHub
Nov 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WAIT] PHPLIB-289 ChangeStreams Examples for Docs (#436)
* PHPLIB-289 ChangeStreams Examples for Docs
parent
0aedcbaf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
DocumentationExamplesTest.php
tests/DocumentationExamplesTest.php
+54
-0
No files found.
tests/DocumentationExamplesTest.php
View file @
60e3ca24
...
@@ -925,6 +925,60 @@ class DocumentationExamplesTest extends FunctionalTestCase
...
@@ -925,6 +925,60 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this
->
assertInventoryCount
(
0
);
$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.
* Return the test collection name.
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment