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
e847b06c
Commit
e847b06c
authored
Mar 12, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-327: ChangeStream::next() should not increment key for the first event
parent
d42c3b4a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
ChangeStream.php
src/ChangeStream.php
+7
-4
WatchFunctionalTest.php
tests/Operation/WatchFunctionalTest.php
+17
-1
No files found.
src/ChangeStream.php
View file @
e847b06c
...
@@ -38,7 +38,8 @@ class ChangeStream implements Iterator
...
@@ -38,7 +38,8 @@ class ChangeStream implements Iterator
private
$resumeToken
;
private
$resumeToken
;
private
$resumeCallable
;
private
$resumeCallable
;
private
$csIt
;
private
$csIt
;
private
$key
;
private
$key
=
0
;
private
$hasAdvanced
=
false
;
const
CURSOR_NOT_FOUND
=
43
;
const
CURSOR_NOT_FOUND
=
43
;
...
@@ -53,8 +54,6 @@ class ChangeStream implements Iterator
...
@@ -53,8 +54,6 @@ class ChangeStream implements Iterator
{
{
$this
->
resumeCallable
=
$resumeCallable
;
$this
->
resumeCallable
=
$resumeCallable
;
$this
->
csIt
=
new
IteratorIterator
(
$cursor
);
$this
->
csIt
=
new
IteratorIterator
(
$cursor
);
$this
->
key
=
0
;
}
}
/**
/**
...
@@ -97,7 +96,10 @@ class ChangeStream implements Iterator
...
@@ -97,7 +96,10 @@ class ChangeStream implements Iterator
$this
->
csIt
->
next
();
$this
->
csIt
->
next
();
if
(
$this
->
valid
())
{
if
(
$this
->
valid
())
{
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
$this
->
key
++
;
if
(
$this
->
hasAdvanced
)
{
$this
->
key
++
;
}
$this
->
hasAdvanced
=
true
;
}
}
}
catch
(
RuntimeException
$e
)
{
}
catch
(
RuntimeException
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
...
@@ -126,6 +128,7 @@ class ChangeStream implements Iterator
...
@@ -126,6 +128,7 @@ class ChangeStream implements Iterator
$this
->
csIt
->
rewind
();
$this
->
csIt
->
rewind
();
if
(
$this
->
valid
())
{
if
(
$this
->
valid
())
{
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
$this
->
resumeToken
=
$this
->
extractResumeToken
(
$this
->
csIt
->
current
());
$this
->
hasAdvanced
=
true
;
}
}
}
catch
(
RuntimeException
$e
)
{
}
catch
(
RuntimeException
$e
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
if
(
strpos
(
$e
->
getMessage
(),
"not master"
)
!==
false
)
{
...
...
tests/Operation/WatchFunctionalTest.php
View file @
e847b06c
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
namespace
MongoDB\Tests\Operation
;
namespace
MongoDB\Tests\Operation
;
use
MongoDB\ChangeStream
;
use
MongoDB\ChangeStream
;
use
MongoDB\Client
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
...
@@ -536,6 +535,23 @@ class WatchFunctionalTest extends FunctionalTestCase
...
@@ -536,6 +535,23 @@ class WatchFunctionalTest extends FunctionalTestCase
];
];
}
}
public
function
testNextAdvancesKey
()
{
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
insertDocument
([
'x'
=>
1
]);
$this
->
insertDocument
([
'x'
=>
2
]);
$changeStream
->
next
();
$this
->
assertSame
(
0
,
$changeStream
->
key
());
$changeStream
->
next
();
$this
->
assertSame
(
1
,
$changeStream
->
key
());
}
private
function
insertDocument
(
$document
)
private
function
insertDocument
(
$document
)
{
{
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$document
);
$insertOne
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$document
);
...
...
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