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
50ef5ed6
Commit
50ef5ed6
authored
Oct 09, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor functional tests to use DropCollection
parent
ed4cfa1c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
22 deletions
+32
-22
AggregateFunctionalTest.php
tests/Collection/CrudSpec/AggregateFunctionalTest.php
+5
-2
FunctionalTestCase.php
tests/Collection/FunctionalTestCase.php
+5
-18
FunctionalTestCase.php
tests/FunctionalTestCase.php
+5
-0
FunctionalTestCase.php
tests/Operation/FunctionalTestCase.php
+17
-2
No files found.
tests/Collection/CrudSpec/AggregateFunctionalTest.php
View file @
50ef5ed6
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Collection\CrudSpec;
...
@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Collection\CrudSpec;
use
MongoDB\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Operation\DropCollection
;
/**
/**
* CRUD spec functional tests for aggregate().
* CRUD spec functional tests for aggregate().
...
@@ -48,7 +49,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
...
@@ -48,7 +49,8 @@ class AggregateFunctionalTest extends FunctionalTestCase
}
}
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
()
.
'_output'
);
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
()
.
'_output'
);
$this
->
dropCollectionIfItExists
(
$outputCollection
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$outputCollection
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
collection
->
aggregate
(
$this
->
collection
->
aggregate
(
array
(
array
(
...
@@ -66,6 +68,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
...
@@ -66,6 +68,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
assertSameDocuments
(
$expected
,
$outputCollection
->
find
());
$this
->
assertSameDocuments
(
$expected
,
$outputCollection
->
find
());
// Manually clean up our output collection
// Manually clean up our output collection
$this
->
dropCollectionIfItExists
(
$outputCollection
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$outputCollection
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
}
}
tests/Collection/FunctionalTestCase.php
View file @
50ef5ed6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
namespace
MongoDB\Tests\Collection
;
namespace
MongoDB\Tests\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Collection
;
use
MongoDB\
Database
;
use
MongoDB\
Operation\DropCollection
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
/**
...
@@ -18,7 +18,8 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
...
@@ -18,7 +18,8 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
parent
::
setUp
();
parent
::
setUp
();
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
());
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
());
$this
->
dropCollectionIfItExists
(
$this
->
collection
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
public
function
tearDown
()
public
function
tearDown
()
...
@@ -27,21 +28,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
...
@@ -27,21 +28,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
return
;
return
;
}
}
$this
->
dropCollectionIfItExists
(
$this
->
collection
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
}
$operation
->
execute
(
$this
->
getPrimaryServer
());
/**
* Drop the collection if it exists.
*
* @param Collection $collection
*/
protected
function
dropCollectionIfItExists
(
Collection
$collection
)
{
$database
=
new
Database
(
$this
->
manager
,
$collection
->
getDatabaseName
());
$collections
=
$database
->
listCollections
(
array
(
'filter'
=>
array
(
'name'
=>
$collection
->
getCollectionName
())));
if
(
iterator_count
(
$collections
)
>
0
)
{
$this
->
assertCommandSucceeded
(
$collection
->
drop
());
}
}
}
}
}
tests/FunctionalTestCase.php
View file @
50ef5ed6
...
@@ -68,6 +68,11 @@ abstract class FunctionalTestCase extends TestCase
...
@@ -68,6 +68,11 @@ abstract class FunctionalTestCase extends TestCase
);
);
}
}
protected
function
getPrimaryServer
()
{
return
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
}
protected
function
getServerVersion
(
ReadPreference
$readPreference
=
null
)
protected
function
getServerVersion
(
ReadPreference
$readPreference
=
null
)
{
{
$cursor
=
$this
->
manager
->
executeCommand
(
$cursor
=
$this
->
manager
->
executeCommand
(
...
...
tests/Operation/FunctionalTestCase.php
View file @
50ef5ed6
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
namespace
MongoDB\Tests\Operation
;
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Collection
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
/**
...
@@ -10,8 +12,21 @@ use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
...
@@ -10,8 +12,21 @@ use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
*/
*/
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
{
{
public
function
getPrimaryServer
()
public
function
setUp
()
{
{
return
$this
->
manager
->
selectServer
(
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
));
parent
::
setUp
();
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
public
function
tearDown
()
{
if
(
$this
->
hasFailed
())
{
return
;
}
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
}
}
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