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
fefdb978
Commit
fefdb978
authored
Feb 20, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve ExplainTest and ExplainFunctionalTest
parent
c7b2b033
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
277 deletions
+60
-277
Explain.php
src/Operation/Explain.php
+4
-8
ExplainFunctionalTest.php
tests/Operation/ExplainFunctionalTest.php
+54
-257
ExplainTest.php
tests/Operation/ExplainTest.php
+2
-12
No files found.
src/Operation/Explain.php
View file @
fefdb978
...
...
@@ -80,17 +80,13 @@ class Explain implements Executable
throw
UnsupportedException
::
explainNotSupported
();
}
if
(
$this
->
explainable
instanceOf
\MongoDB\Operation\Distinct
)
{
if
(
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\Distinct
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
throw
UnsupportedException
::
explainNotSupported
();
}
}
if
(
$this
->
explainable
instanceOf
\MongoDB\Operation\FindAndModify
)
{
if
(
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\FindAndModify
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
throw
UnsupportedException
::
explainNotSupported
();
}
}
$cmd
=
[
'explain'
=>
$this
->
explainable
->
getCommandDocument
()];
...
...
tests/Operation/ExplainFunctionalTest.php
View file @
fefdb978
...
...
@@ -22,65 +22,10 @@ class ExplainFunctionalTest extends FunctionalTestCase
}
}
public
function
testCountAllPlansExecution
()
{
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'x'
=>
0
],
[
'x'
=>
1
],
[
'x'
=>
2
],
[
'y'
=>
3
]
]);
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_ALL_PLANS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testCountDefaultVerbosity
()
{
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'x'
=>
0
],
[
'x'
=>
1
],
[
'x'
=>
2
],
[
'y'
=>
3
]
]);
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testCountExecutionStats
()
{
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'x'
=>
0
],
[
'x'
=>
1
],
[
'x'
=>
2
],
[
'y'
=>
3
]
]);
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testCountQueryPlanner
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testCount
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'x'
=>
0
],
...
...
@@ -91,62 +36,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
}
public
function
testDistinctAllPlansExecution
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
}
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_ALL_PLANS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testDistinctDefaultVerbosity
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
}
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'typeMap'
=>
[
'root'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testDistinctExecutionStats
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
}
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testDistinctQueryPlanner
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testDistinct
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
...
...
@@ -154,62 +53,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
}
public
function
testFindAndModifyAllPlansExecution
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
}
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_ALL_PLANS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindAndModifyDefaultVerbosity
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
}
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'typeMap'
=>
[
'root'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindAndModifyExecutionStats
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindAndModifyQueryPlanner
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindAndModify
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
...
...
@@ -217,69 +70,31 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'typeMap'
=>
[
'roo
t'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'documen
t'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testFindAllPlansExecution
()
{
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_ALL_PLANS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindDefaultVerbosity
()
{
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindExecutionStats
()
{
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
public
function
testFindQueryPlanner
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFind
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'typeMap'
=>
[
'roo
t'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'documen
t'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testFindMaxAwait
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindMaxAwait
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'maxAwaitTimeMS option is not supported'
);
...
...
@@ -312,67 +127,49 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
Find
(
$databaseName
,
$cappedCollectionName
,
[],
[
'cursorType'
=>
Find
::
TAILABLE_AWAIT
,
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'
typeMap'
=>
[
'roo
t'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'
verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'documen
t'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testFindOneAllPlansExecution
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindOne
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
1
);
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_ALL_PLANS
,
'typeMap'
=>
[
'roo
t'
=>
'array'
]]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
$verbosity
,
'typeMap'
=>
[
'root'
=>
'array'
,
'documen
t'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testFindOneDefaultVerbosity
()
public
function
provideVerbosityInformation
()
{
$this
->
createFixtures
(
1
);
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
return
[
[
Explain
::
VERBOSITY_ALL_PLANS
,
true
,
true
],
[
Explain
::
VERBOSITY_EXEC_STATS
,
true
,
false
],
[
Explain
::
VERBOSITY_QUERY
,
false
,
false
]
];
}
p
ublic
function
testFindOneExecutionStats
(
)
p
rivate
function
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
$this
->
createFixtures
(
1
);
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]
]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
])
);
$this
->
assertArrayHasKey
(
'queryPlanner'
,
$result
);
if
(
$executionStatsExpected
)
{
$this
->
assertArrayHasKey
(
'executionStats'
,
$result
);
if
(
$allPlansExecutionExpected
)
{
$this
->
assertArrayHasKey
(
'allPlansExecution'
,
$result
[
'executionStats'
]);
}
else
{
$this
->
assertArrayNotHasKey
(
'allPlansExecution'
,
$result
[
'executionStats'
]);
}
}
else
{
$this
->
assertArrayNotHasKey
(
'executionStats'
,
$result
);
}
public
function
testFindOneQueryPlanner
()
{
$this
->
createFixtures
(
1
);
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
}
/**
...
...
tests/Operation/ExplainTest.php
View file @
fefdb978
...
...
@@ -12,19 +12,9 @@ class ExplainTest extends TestCase
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecks
ForCount
(
array
$options
)
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
$explainable
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),[]);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public
function
testConstructorOptionTypeChecksForDistinct
(
array
$options
)
{
$explainable
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainable
=
$this
->
createMock
(
'MongoDB\Operation\Explainable'
);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
}
...
...
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