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
7 years ago
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
...
@@ -80,17 +80,13 @@ class Explain implements Executable
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
if
(
$this
->
explainable
instanceOf
\MongoDB\Operation\Distinct
)
{
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\Distinct
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
if
(
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDistinct
))
{
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
}
if
(
$this
->
explainable
instanceOf
\MongoDB\Operation\FindAndModify
)
{
if
(
$this
->
explainable
instanceof
\MongoDB\Operation\FindAndModify
&&
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
if
(
!
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForFindAndModify
))
{
throw
UnsupportedException
::
explainNotSupported
();
throw
UnsupportedException
::
explainNotSupported
();
}
}
}
$cmd
=
[
'explain'
=>
$this
->
explainable
->
getCommandDocument
()];
$cmd
=
[
'explain'
=>
$this
->
explainable
->
getCommandDocument
()];
...
...
This diff is collapsed.
Click to expand it.
tests/Operation/ExplainFunctionalTest.php
View file @
fefdb978
...
@@ -22,65 +22,10 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -22,65 +22,10 @@ class ExplainFunctionalTest extends FunctionalTestCase
}
}
}
}
public
function
testCountAllPlansExecution
()
/**
{
* @dataProvider provideVerbosityInformation
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
*/
[
'x'
=>
0
],
public
function
testCount
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
[
'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
()
{
{
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
$insertMany
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
[
'x'
=>
0
],
[
'x'
=>
0
],
...
@@ -91,62 +36,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -91,62 +36,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$insertMany
->
execute
(
$this
->
getPrimaryServer
());
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'x'
=>
[
'$gte'
=>
1
]],
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'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
->
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'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
}
public
function
testDistinctExecutionStats
()
/**
{
* @dataProvider provideVerbosityInformation
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
*/
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
public
function
testDistinct
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
}
$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
()
{
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
$this
->
markTestSkipped
(
'Distinct is not supported on servers with version < 3.2'
);
...
@@ -154,62 +53,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -154,62 +53,16 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[]);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_QUERY
,
'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
->
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'
]]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$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'
);
}
}
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
/**
* @dataProvider provideVerbosityInformation
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]]);
*/
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
public
function
testFindAndModify
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
$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
()
{
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
$this
->
markTestSkipped
(
'FindAndModify is not supported on servers with version < 3.2'
);
...
@@ -217,69 +70,31 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -217,69 +70,31 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
]);
$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
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
}
}
public
function
testFindAllPlansExecution
()
/**
{
* @dataProvider provideVerbosityInformation
$this
->
createFixtures
(
3
);
*/
public
function
testFind
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
$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
()
{
{
$this
->
createFixtures
(
3
);
$this
->
createFixtures
(
3
);
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]);
$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
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertFalse
(
array_key_exists
(
'executionStats'
,
$result
));
}
}
public
function
testFindMaxAwait
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindMaxAwait
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.2.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'maxAwaitTimeMS option is not supported'
);
$this
->
markTestSkipped
(
'maxAwaitTimeMS option is not supported'
);
...
@@ -312,67 +127,49 @@ class ExplainFunctionalTest extends FunctionalTestCase
...
@@ -312,67 +127,49 @@ class ExplainFunctionalTest extends FunctionalTestCase
$operation
=
new
Find
(
$databaseName
,
$cappedCollectionName
,
[],
[
'cursorType'
=>
Find
::
TAILABLE_AWAIT
,
'maxAwaitTimeMS'
=>
$maxAwaitTimeMS
]);
$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
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
}
public
function
testFindOneAllPlansExecution
()
/**
* @dataProvider provideVerbosityInformation
*/
public
function
testFindOne
(
$verbosity
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
{
$this
->
createFixtures
(
1
);
$this
->
createFixtures
(
1
);
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
$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
());
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
$this
->
assertTrue
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
]));
}
}
public
function
testFindOneDefaultVerbosity
()
public
function
provideVerbosityInformation
()
{
{
$this
->
createFixtures
(
1
);
return
[
[
Explain
::
VERBOSITY_ALL_PLANS
,
true
,
true
],
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]);
[
Explain
::
VERBOSITY_EXEC_STATS
,
true
,
false
],
[
Explain
::
VERBOSITY_QUERY
,
false
,
false
]
$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'
]));
}
}
p
ublic
function
testFindOneExecutionStats
(
)
p
rivate
function
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
)
{
{
$this
->
createFixtures
(
1
);
$this
->
assertArrayHasKey
(
'queryPlanner'
,
$result
);
if
(
$executionStatsExpected
)
{
$operation
=
new
FindOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[]
);
$this
->
assertArrayHasKey
(
'executionStats'
,
$result
);
if
(
$allPlansExecutionExpected
)
{
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
,
[
'verbosity'
=>
Explain
::
VERBOSITY_EXEC_STATS
,
'typeMap'
=>
[
'root'
=>
'array'
]
]);
$this
->
assertArrayHasKey
(
'allPlansExecution'
,
$result
[
'executionStats'
]);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
}
else
{
$this
->
assertArrayNotHasKey
(
'allPlansExecution'
,
$result
[
'executionStats'
]);
$this
->
assertTrue
(
array_key_exists
(
'queryPlanner'
,
$result
));
}
$this
->
assertTrue
(
array_key_exists
(
'executionStats'
,
$result
));
}
else
{
$this
->
assertFalse
(
array_key_exists
(
'allPlansExecution'
,
$result
[
'executionStats'
])
);
$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
));
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
tests/Operation/ExplainTest.php
View file @
fefdb978
...
@@ -12,19 +12,9 @@ class ExplainTest extends TestCase
...
@@ -12,19 +12,9 @@ class ExplainTest extends TestCase
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
* @dataProvider provideInvalidConstructorOptions
*/
*/
public
function
testConstructorOptionTypeChecks
ForCount
(
array
$options
)
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
{
$explainable
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),[]);
$explainable
=
$this
->
createMock
(
'MongoDB\Operation\Explainable'
);
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'
,
[]);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
new
Explain
(
$this
->
getDatabaseName
(),
$explainable
,
$options
);
}
}
...
...
This diff is collapsed.
Click to expand it.
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