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
cf351325
Commit
cf351325
authored
Sep 27, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-107: Do not throw when dropping nonexistent collection
parent
c9f4c850
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
1 deletion
+88
-1
DropCollection.php
src/Operation/DropCollection.php
+11
-1
DropCollectionFunctionalTest.php
tests/Operation/DropCollectionFunctionalTest.php
+60
-0
FunctionalTestCase.php
tests/Operation/FunctionalTestCase.php
+17
-0
No files found.
src/Operation/DropCollection.php
View file @
cf351325
...
@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
...
@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Exception\RuntimeException
;
/**
/**
...
@@ -40,7 +41,16 @@ class DropCollection implements Executable
...
@@ -40,7 +41,16 @@ class DropCollection implements Executable
*/
*/
public
function
execute
(
Server
$server
)
public
function
execute
(
Server
$server
)
{
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)));
try
{
$cursor
=
$server
->
executeCommand
(
$this
->
databaseName
,
new
Command
(
array
(
'drop'
=>
$this
->
collectionName
)));
}
catch
(
DriverRuntimeException
$e
)
{
if
(
$e
->
getMessage
()
===
'ns not found'
)
{
$result
=
(
object
)
[
'ok'
=>
0
,
'errmsg'
=>
'ns not found'
];
}
throw
$e
;
}
$result
=
current
(
$cursor
->
toArray
());
$result
=
current
(
$cursor
->
toArray
());
if
(
empty
(
$result
->
ok
))
{
if
(
empty
(
$result
->
ok
))
{
...
...
tests/Operation/DropCollectionFunctionalTest.php
0 → 100644
View file @
cf351325
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Driver\Server
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\ListCollections
;
class
DropCollectionFunctionalTest
extends
FunctionalTestCase
{
public
function
testDropExistingCollection
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$server
=
$this
->
getPrimaryServer
();
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$server
);
$this
->
assertCollectionDoesNotExist
(
$server
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
}
/**
* @depends testDropExistingCollection
*/
public
function
testDropNonexistentCollection
()
{
$server
=
$this
->
getPrimaryServer
();
$this
->
assertCollectionDoesNotExist
(
$server
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$server
);
}
/**
* Asserts that a collection with the given name does not exist on the
* server.
*
* @param Server $server
* @param string $databaseName
* @param string $collectionName
*/
private
function
assertCollectionDoesNotExist
(
Server
$server
,
$databaseName
,
$collectionName
)
{
$operation
=
new
ListCollections
(
$databaseName
);
$collections
=
$operation
->
execute
(
$server
);
$foundCollection
=
null
;
foreach
(
$collections
as
$collection
)
{
if
(
$collection
->
getName
()
===
$collectionName
)
{
$foundCollection
=
$collection
;
break
;
}
}
$this
->
assertNull
(
$foundCollection
,
sprintf
(
'Collection %s exists on the server'
,
$collectionName
));
}
}
tests/Operation/FunctionalTestCase.php
0 → 100644
View file @
cf351325
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
* Base class for Operation functional tests.
*/
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
{
public
function
getPrimaryServer
()
{
return
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
}
}
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