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
28da2e1e
Commit
28da2e1e
authored
Mar 26, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-71: Collection drop methods
parent
6c1d6ac1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
2 deletions
+32
-2
Collection.php
src/Collection.php
+5
-1
Database.php
src/Database.php
+6
-1
CollectionFunctionalTest.php
tests/CollectionFunctionalTest.php
+10
-0
DatabaseFunctionalTest.php
tests/DatabaseFunctionalTest.php
+11
-0
No files found.
src/Collection.php
View file @
28da2e1e
...
...
@@ -334,11 +334,15 @@ class Collection
/**
* Drop this collection.
*
* @see http://docs.mongodb.org/manual/reference/command/drop/
* @return Result
*/
public
function
drop
()
{
// TODO
$command
=
new
Command
(
array
(
'drop'
=>
$this
->
collname
));
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
return
$this
->
manager
->
executeCommand
(
$this
->
dbname
,
$command
,
$readPreference
);
}
/**
...
...
src/Database.php
View file @
28da2e1e
...
...
@@ -66,12 +66,17 @@ class Database
/**
* Drop a collection within this database.
*
* @see http://docs.mongodb.org/manual/reference/command/drop/
* @param string $collectionName
* @return Result
*/
public
function
dropCollection
(
$collectionName
)
{
// TODO
$collectionName
=
(
string
)
$collectionName
;
$command
=
new
Command
(
array
(
'drop'
=>
$collectionName
));
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
return
$this
->
manager
->
executeCommand
(
$this
->
databaseName
,
$command
,
$readPreference
);
}
/**
...
...
tests/CollectionFunctionalTest.php
View file @
28da2e1e
...
...
@@ -17,6 +17,16 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
collection
->
deleteMany
(
array
());
}
public
function
testDrop
()
{
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
collection
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
function
testInsertAndRetrieve
()
{
$generator
=
new
FixtureGenerator
();
...
...
tests/DatabaseFunctionalTest.php
View file @
28da2e1e
...
...
@@ -20,4 +20,15 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
public
function
testDropCollection
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$commandResult
=
$database
->
dropCollection
(
$this
->
getCollectionName
());
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
}
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