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
10ea91c2
Commit
10ea91c2
authored
Mar 24, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-65: Database drop methods
parent
b85b91fb
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
4 deletions
+78
-4
Client.php
src/Client.php
+7
-3
Database.php
src/Database.php
+6
-1
ClientFunctionalTest.php
tests/ClientFunctionalTest.php
+22
-0
DatabaseFunctionalTest.php
tests/DatabaseFunctionalTest.php
+23
-0
FunctionalTestCase.php
tests/FunctionalTestCase.php
+20
-0
No files found.
src/Client.php
View file @
10ea91c2
...
...
@@ -2,8 +2,7 @@
namespace
MongoDB
;
use
MongoDB\Collection
;
use
MongoDB\Database
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Result
;
...
...
@@ -35,12 +34,17 @@ class Client
/**
* Drop a database.
*
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
* @param string $databaseName
* @return Result
*/
public
function
dropDatabase
(
$databaseName
)
{
// TODO
$databaseName
=
(
string
)
$databaseName
;
$command
=
new
Command
(
array
(
'dropDatabase'
=>
1
));
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
return
$this
->
manager
->
executeCommand
(
$databaseName
,
$command
,
$readPreference
);
}
/**
...
...
src/Database.php
View file @
10ea91c2
...
...
@@ -3,6 +3,7 @@
namespace
MongoDB
;
use
MongoDB\Collection
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Result
;
...
...
@@ -51,11 +52,15 @@ class Database
/**
* Drop this database.
*
* @see http://docs.mongodb.org/manual/reference/command/dropDatabase/
* @return Result
*/
public
function
drop
()
{
// TODO
$command
=
new
Command
(
array
(
'dropDatabase'
=>
1
));
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
return
$this
->
manager
->
executeCommand
(
$this
->
databaseName
,
$command
,
$readPreference
);
}
/**
...
...
tests/ClientFunctionalTest.php
0 → 100644
View file @
10ea91c2
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Client
;
/**
* Functional tests for the Client class.
*/
class
ClientFunctionalTest
extends
FunctionalTestCase
{
public
function
testDropDatabase
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$client
=
new
Client
(
$this
->
getUri
());
$commandResult
=
$client
->
dropDatabase
(
$this
->
getDatabaseName
());
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
}
tests/DatabaseFunctionalTest.php
0 → 100644
View file @
10ea91c2
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Client
;
use
MongoDB\Database
;
/**
* Functional tests for the Database class.
*/
class
DatabaseFunctionalTest
extends
FunctionalTestCase
{
public
function
testDrop
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$commandResult
=
$database
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
}
tests/FunctionalTestCase.php
View file @
10ea91c2
...
...
@@ -2,7 +2,9 @@
namespace
MongoDB\Tests
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Result
;
abstract
class
FunctionalTestCase
extends
TestCase
{
...
...
@@ -12,4 +14,22 @@ abstract class FunctionalTestCase extends TestCase
{
$this
->
manager
=
new
Manager
(
$this
->
getUri
());
}
public
function
assertCollectionCount
(
$namespace
,
$count
)
{
list
(
$databaseName
,
$collectionName
)
=
explode
(
'.'
,
$namespace
,
2
);
$result
=
$this
->
manager
->
executeCommand
(
$databaseName
,
new
Command
(
array
(
'count'
=>
$collectionName
)));
$document
=
$result
->
toArray
();
$this
->
assertArrayHasKey
(
'n'
,
$document
);
$this
->
assertEquals
(
$count
,
$document
[
'n'
]);
}
public
function
assertCommandSucceeded
(
Result
$result
)
{
$document
=
$result
->
toArray
();
$this
->
assertArrayHasKey
(
'ok'
,
$document
);
$this
->
assertEquals
(
1
,
$document
[
'ok'
]);
}
}
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