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
abffc315
Commit
abffc315
authored
Sep 28, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #32
parents
c2f4e5e7
3f12bc6a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
148 additions
and
2 deletions
+148
-2
DropCollection.php
src/Operation/DropCollection.php
+11
-1
ClientFunctionalTest.php
tests/ClientFunctionalTest.php
+2
-1
DropCollectionFunctionalTest.php
tests/Operation/DropCollectionFunctionalTest.php
+60
-0
DropDatabaseFunctionalTest.php
tests/Operation/DropDatabaseFunctionalTest.php
+58
-0
FunctionalTestCase.php
tests/Operation/FunctionalTestCase.php
+17
-0
No files found.
src/Operation/DropCollection.php
View file @
abffc315
...
...
@@ -4,6 +4,7 @@ namespace MongoDB\Operation;
use
MongoDB\Driver\Command
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Exception\RuntimeException
;
/**
...
...
@@ -40,7 +41,16 @@ class DropCollection implements Executable
*/
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
());
if
(
empty
(
$result
->
ok
))
{
...
...
tests/ClientFunctionalTest.php
View file @
abffc315
...
...
@@ -59,6 +59,7 @@ class ClientFunctionalTest extends FunctionalTestCase
* the given name is found, it will be passed to the callback, which may
* perform additional assertions.
*
* @param string $databaseName
* @param callable $callback
*/
private
function
assertDatabaseExists
(
$databaseName
,
$callback
=
null
)
...
...
@@ -78,7 +79,7 @@ class ClientFunctionalTest extends FunctionalTestCase
}
}
$this
->
assertNotNull
(
$foundDatabase
,
sprintf
(
'
Found %s database
on the server'
,
$databaseName
));
$this
->
assertNotNull
(
$foundDatabase
,
sprintf
(
'
Database %s does not exist
on the server'
,
$databaseName
));
if
(
$callback
!==
null
)
{
call_user_func
(
$callback
,
$foundDatabase
);
...
...
tests/Operation/DropCollectionFunctionalTest.php
0 → 100644
View file @
abffc315
<?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/DropDatabaseFunctionalTest.php
0 → 100644
View file @
abffc315
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Driver\Server
;
use
MongoDB\Operation\DropDatabase
;
use
MongoDB\Operation\ListDatabases
;
class
DropDatabaseFunctionalTest
extends
FunctionalTestCase
{
public
function
testDropExistingDatabase
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$server
=
$this
->
getPrimaryServer
();
$operation
=
new
DropDatabase
(
$this
->
getDatabaseName
());
$operation
->
execute
(
$server
);
$this
->
assertDatabaseDoesNotExist
(
$server
,
$this
->
getDatabaseName
());
}
/**
* @depends testDropExistingDatabase
*/
public
function
testDropNonexistentDatabase
()
{
$server
=
$this
->
getPrimaryServer
();
$this
->
assertDatabaseDoesNotExist
(
$server
,
$this
->
getDatabaseName
());
$operation
=
new
DropDatabase
(
$this
->
getDatabaseName
());
$operation
->
execute
(
$server
);
}
/**
* Asserts that a database with the given name does not exist on the server.
*
* @param Server $server
* @param string $databaseName
*/
private
function
assertDatabaseDoesNotExist
(
Server
$server
,
$databaseName
)
{
$operation
=
new
ListDatabases
();
$databases
=
$operation
->
execute
(
$server
);
$foundDatabase
=
null
;
foreach
(
$databases
as
$database
)
{
if
(
$database
->
getName
()
===
$databaseName
)
{
$foundDatabase
=
$database
;
break
;
}
}
$this
->
assertNull
(
$foundDatabase
,
sprintf
(
'Database %s exists on the server'
,
$databaseName
));
}
}
tests/Operation/FunctionalTestCase.php
0 → 100644
View file @
abffc315
<?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