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
c6a2df9a
Commit
c6a2df9a
authored
Feb 21, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement getCommandDocument for all findAndModify operations
parent
cbb7fc7c
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
13 deletions
+86
-13
Explain.php
src/Operation/Explain.php
+10
-2
FindOneAndDelete.php
src/Operation/FindOneAndDelete.php
+6
-1
FindOneAndReplace.php
src/Operation/FindOneAndReplace.php
+6
-1
FindOneAndUpdate.php
src/Operation/FindOneAndUpdate.php
+6
-1
CountFunctionalTest.php
tests/Operation/CountFunctionalTest.php
+0
-1
DistinctFunctionalTest.php
tests/Operation/DistinctFunctionalTest.php
+0
-1
ExplainFunctionalTest.php
tests/Operation/ExplainFunctionalTest.php
+57
-3
ExplainTest.php
tests/Operation/ExplainTest.php
+1
-2
FindAndModifyFunctionalTest.php
tests/Operation/FindAndModifyFunctionalTest.php
+0
-1
No files found.
src/Operation/Explain.php
View file @
c6a2df9a
...
@@ -80,11 +80,11 @@ class Explain implements Executable
...
@@ -80,11 +80,11 @@ class Explain implements Executable
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\
Distinct
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
if
(
$this
->
explainable
instanceof
Distinct
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\FindAndModify
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
if
(
$this
->
isFindAndModify
(
$this
->
explainable
)
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
...
@@ -102,4 +102,12 @@ class Explain implements Executable
...
@@ -102,4 +102,12 @@ class Explain implements Executable
return
current
(
$cursor
->
toArray
());
return
current
(
$cursor
->
toArray
());
}
}
private
function
isFindAndModify
(
$explainable
)
{
if
(
$explainable
instanceof
FindAndModify
||
$explainable
instanceof
FindOneAndDelete
||
$explainable
instanceof
FindOneAndReplace
||
$explainable
instanceof
FindOneAndUpdate
)
{
return
true
;
}
return
false
;
}
}
}
src/Operation/FindOneAndDelete.php
View file @
c6a2df9a
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::findOneAndDelete()
* @see \MongoDB\Collection::findOneAndDelete()
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
*/
*/
class
FindOneAndDelete
implements
Executable
class
FindOneAndDelete
implements
Executable
,
Explainable
{
{
private
$findAndModify
;
private
$findAndModify
;
...
@@ -105,4 +105,9 @@ class FindOneAndDelete implements Executable
...
@@ -105,4 +105,9 @@ class FindOneAndDelete implements Executable
{
{
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
{
return
$this
->
findAndModify
->
getCommandDocument
();
}
}
}
src/Operation/FindOneAndReplace.php
View file @
c6a2df9a
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::findOneAndReplace()
* @see \MongoDB\Collection::findOneAndReplace()
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
*/
*/
class
FindOneAndReplace
implements
Executable
class
FindOneAndReplace
implements
Executable
,
Explainable
{
{
const
RETURN_DOCUMENT_BEFORE
=
1
;
const
RETURN_DOCUMENT_BEFORE
=
1
;
const
RETURN_DOCUMENT_AFTER
=
2
;
const
RETURN_DOCUMENT_AFTER
=
2
;
...
@@ -148,4 +148,9 @@ class FindOneAndReplace implements Executable
...
@@ -148,4 +148,9 @@ class FindOneAndReplace implements Executable
{
{
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
{
return
$this
->
findAndModify
->
getCommandDocument
();
}
}
}
src/Operation/FindOneAndUpdate.php
View file @
c6a2df9a
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
...
@@ -29,7 +29,7 @@ use MongoDB\Exception\UnsupportedException;
* @see \MongoDB\Collection::findOneAndUpdate()
* @see \MongoDB\Collection::findOneAndUpdate()
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
* @see http://docs.mongodb.org/manual/reference/command/findAndModify/
*/
*/
class
FindOneAndUpdate
implements
Executable
class
FindOneAndUpdate
implements
Executable
,
Explainable
{
{
const
RETURN_DOCUMENT_BEFORE
=
1
;
const
RETURN_DOCUMENT_BEFORE
=
1
;
const
RETURN_DOCUMENT_AFTER
=
2
;
const
RETURN_DOCUMENT_AFTER
=
2
;
...
@@ -151,4 +151,9 @@ class FindOneAndUpdate implements Executable
...
@@ -151,4 +151,9 @@ class FindOneAndUpdate implements Executable
{
{
return
$this
->
findAndModify
->
execute
(
$server
);
return
$this
->
findAndModify
->
execute
(
$server
);
}
}
public
function
getCommandDocument
()
{
return
$this
->
findAndModify
->
getCommandDocument
();
}
}
}
tests/Operation/CountFunctionalTest.php
View file @
c6a2df9a
...
@@ -4,7 +4,6 @@ namespace MongoDB\Tests\Operation;
...
@@ -4,7 +4,6 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Operation\Count
;
use
MongoDB\Operation\Count
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\Explain
;
use
MongoDB\Operation\InsertMany
;
use
MongoDB\Operation\InsertMany
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
...
...
tests/Operation/DistinctFunctionalTest.php
View file @
c6a2df9a
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
namespace
MongoDB\Tests\Operation
;
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Distinct
;
use
MongoDB\Operation\Distinct
;
use
MongoDB\Operation\Explain
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
...
...
tests/Operation/ExplainFunctionalTest.php
View file @
c6a2df9a
...
@@ -12,6 +12,9 @@ use MongoDB\Operation\Explain;
...
@@ -12,6 +12,9 @@ use MongoDB\Operation\Explain;
use
MongoDB\Operation\Find
;
use
MongoDB\Operation\Find
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Operation\FindOne
;
use
MongoDB\Operation\FindOne
;
use
MongoDB\Operation\FindOneAndDelete
;
use
MongoDB\Operation\FindOneAndReplace
;
use
MongoDB\Operation\FindOneAndUpdate
;
use
MongoDB\Operation\Update
;
use
MongoDB\Operation\Update
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
...
@@ -101,7 +104,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -101,7 +104,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
{
{
$this
->
createFixtures
(
3
);
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
,
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
...
@@ -159,7 +162,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -159,7 +162,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this
->
getDatabaseName
(),
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$this
->
getCollectionName
(),
[],
[],
[
'
readConcern'
=>
$this
->
createDefaultReadConcern
(),
'modifiers'
=>
[
'$max'
=>
[
'_id'
=>
2.2
]]]
[
'
modifiers'
=>
[
'$orderby'
=>
[
'_id'
=>
1
]]]
);
);
(
new
CommandObserver
)
->
observe
(
(
new
CommandObserver
)
->
observe
(
...
@@ -168,7 +171,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -168,7 +171,7 @@ class ExplainFunctionalTest extends FunctionalTestCase
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
},
},
function
(
stdClass
$command
)
{
function
(
stdClass
$command
)
{
$this
->
assertObjectHasAttribute
(
'
max
'
,
$command
->
explain
);
$this
->
assertObjectHasAttribute
(
'
sort
'
,
$command
->
explain
);
$this
->
assertObjectNotHasAttribute
(
'modifiers'
,
$command
->
explain
);
$this
->
assertObjectNotHasAttribute
(
'modifiers'
,
$command
->
explain
);
}
}
);
);
...
@@ -190,6 +193,57 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -190,6 +193,57 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindOneAndDelete
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Explaining findOneAndDelete command requires server version >= 3.2'
);
}
$operation
=
new
FindOneAndDelete
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindOneAndReplace
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Explaining findOneAndReplace command requires server version >= 3.2'
);
}
$operation
=
new
FindOneAndReplace
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
1.1
],
[
'x'
=>
5
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindOneAndUpdate
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Explaining findOneAndUpdate command requires server version >= 3.2'
);
}
$operation
=
new
FindOneAndUpdate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'$rename'
=>
[
'x'
=>
'y'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
/**
/**
* @dataProvider provideVerbosityInformation
* @dataProvider provideVerbosityInformation
*/
*/
...
...
tests/Operation/ExplainTest.php
View file @
c6a2df9a
...
@@ -9,13 +9,12 @@ use MongoDB\Operation\Explain;
...
@@ -9,13 +9,12 @@ use MongoDB\Operation\Explain;
class
ExplainTest
extends
TestCase
class
ExplainTest
extends
TestCase
{
{
/**
/**
* @requires PHPUnit 5.4.0
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
* @dataProvider provideInvalidConstructorOptions
*/
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
{
$explainable
=
$this
->
createMock
(
'MongoDB\Operation\Explainable'
);
$explainable
=
$this
->
getMockBuilder
(
'MongoDB\Operation\Explainable'
)
->
getMock
(
);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
}
}
...
...
tests/Operation/FindAndModifyFunctionalTest.php
View file @
c6a2df9a
...
@@ -4,7 +4,6 @@ namespace MongoDB\Tests\Operation;
...
@@ -4,7 +4,6 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Model\BSONDocument
;
use
MongoDB\Model\BSONDocument
;
use
MongoDB\Operation\Explain
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Tests\CommandObserver
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
use
stdClass
;
...
...
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