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
0cd9709a
Commit
0cd9709a
authored
Nov 14, 2015
by
Anton Tuyakhov
Committed by
Jeremy Mikola
Dec 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-153: Add Database::command() helper
parent
ae97a8d9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
Database.php
src/Database.php
+26
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+23
-0
No files found.
src/Database.php
View file @
0cd9709a
...
...
@@ -92,6 +92,32 @@ class Database
return
$this
->
databaseName
;
}
/**
* Execute a command on this database.
*
* @param array|object $command Command document
* @param ReadPreference|null $readPreference Read preference
* @return Cursor
*/
public
function
command
(
$command
,
ReadPreference
$readPreference
=
null
)
{
if
(
!
is_array
(
$command
)
&&
!
is_object
(
$command
))
{
throw
new
InvalidArgumentTypeException
(
'$command'
,
$command
,
'array or object'
);
}
if
(
!
$command
instanceof
Command
)
{
$command
=
new
Command
(
$command
);
}
if
(
!
isset
(
$readPreference
))
{
$readPreference
=
$this
->
readPreference
;
}
$server
=
$this
->
manager
->
selectServer
(
$readPreference
);
return
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
}
/**
* Create a new collection explicitly.
*
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
0cd9709a
...
...
@@ -64,6 +64,29 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
database
->
getDatabaseName
());
}
public
function
testCommand
()
{
$command
=
[
'isMaster'
=>
1
];
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$cursor
=
$this
->
database
->
command
(
$command
,
$readPreference
);
$this
->
assertInstanceOf
(
'MongoDB\Driver\Cursor'
,
$cursor
);
$commandResult
=
current
(
$cursor
->
toArray
());
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertTrue
(
isset
(
$commandResult
->
ismaster
));
$this
->
assertTrue
(
$commandResult
->
ismaster
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentValues
*/
public
function
testCommandCommandArgumentTypeCheck
(
$command
)
{
$this
->
database
->
command
(
$command
);
}
public
function
testDrop
()
{
$bulkWrite
=
new
BulkWrite
();
...
...
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