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
45190ee1
Commit
45190ee1
authored
Nov 02, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add create/drop collection helpers in base FunctionalTestCase
parent
ba0b611a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
53 additions
and
58 deletions
+53
-58
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+2
-7
FunctionalTestCase.php
tests/Collection/FunctionalTestCase.php
+0
-9
DocumentationExamplesTest.php
tests/DocumentationExamplesTest.php
+0
-10
FunctionalTestCase.php
tests/FunctionalTestCase.php
+41
-0
AggregateFunctionalTest.php
tests/Operation/AggregateFunctionalTest.php
+1
-4
FindFunctionalTest.php
tests/Operation/FindFunctionalTest.php
+1
-4
FunctionalTestCase.php
tests/Operation/FunctionalTestCase.php
+0
-10
MapReduceFunctionalTest.php
tests/Operation/MapReduceFunctionalTest.php
+4
-5
ModifyCollectionFunctionalTest.php
tests/Operation/ModifyCollectionFunctionalTest.php
+1
-3
WatchFunctionalTest.php
tests/Operation/WatchFunctionalTest.php
+3
-6
No files found.
tests/Collection/CollectionFunctionalTest.php
View file @
45190ee1
...
...
@@ -10,7 +10,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Operation\Count
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\MapReduce
;
use
MongoDB\Tests\CommandObserver
;
use
Exception
;
...
...
@@ -111,9 +110,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
skipIfTransactionsAreNotSupported
();
// Collection must be created before the transaction starts
$options
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
createCollection
();
$session
=
$this
->
manager
->
startSession
();
$session
->
startTransaction
();
...
...
@@ -219,9 +216,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this
->
skipIfTransactionsAreNotSupported
();
// Collection must be created before the transaction starts
$options
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
createCollection
();
$session
=
$this
->
manager
->
startSession
();
$session
->
startTransaction
();
...
...
tests/Collection/FunctionalTestCase.php
View file @
45190ee1
...
...
@@ -30,13 +30,4 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
$this
->
dropCollection
();
}
private
function
dropCollection
()
{
$options
=
version_compare
(
$this
->
getServerVersion
(),
'3.4.0'
,
'>='
)
?
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)]
:
[];
$this
->
collection
->
drop
(
$options
);
}
}
tests/DocumentationExamplesTest.php
View file @
45190ee1
...
...
@@ -1496,14 +1496,4 @@ class DocumentationExamplesTest extends FunctionalTestCase
{
$this
->
assertCollectionCount
(
$this
->
getDatabaseName
()
.
'.'
.
$this
->
getCollectionName
(),
$count
);
}
private
function
dropCollection
()
{
$options
=
version_compare
(
$this
->
getServerVersion
(),
'3.4.0'
,
'>='
)
?
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)]
:
[];
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
tests/FunctionalTestCase.php
View file @
45190ee1
...
...
@@ -8,7 +8,10 @@ use MongoDB\Driver\Manager;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\Query
;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\Exception\CommandException
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\DropCollection
;
use
stdClass
;
use
UnexpectedValueException
;
...
...
@@ -48,6 +51,44 @@ abstract class FunctionalTestCase extends TestCase
$this
->
assertEquals
((
string
)
$expectedObjectId
,
(
string
)
$actualObjectId
);
}
/**
* Creates the test collection with the specified options.
*
* If the "writeConcern" option is not specified but is supported by the
* server, a majority write concern will be used. This is helpful for tests
* using transactions or secondary reads.
*
* @param array $options
*/
protected
function
createCollection
(
array
$options
=
[])
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.4.0'
,
'>='
))
{
$options
+=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
}
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
/**
* Drops the test collection with the specified options.
*
* If the "writeConcern" option is not specified but is supported by the
* server, a majority write concern will be used. This is helpful for tests
* using transactions or secondary reads.
*
* @param array $options
*/
protected
function
dropCollection
(
array
$options
=
[])
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.4.0'
,
'>='
))
{
$options
+=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
}
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
protected
function
getFeatureCompatibilityVersion
(
ReadPreference
$readPreference
=
null
)
{
if
(
$this
->
isShardedCluster
())
{
...
...
tests/Operation/AggregateFunctionalTest.php
View file @
45190ee1
...
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\Exception\RuntimeException
;
use
MongoDB\Operation\Aggregate
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Tests\CommandObserver
;
use
ArrayIterator
;
use
Exception
;
...
...
@@ -282,9 +281,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
skipIfTransactionsAreNotSupported
();
// Collection must be created before the transaction starts
$options
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
createCollection
();
$session
=
$this
->
manager
->
startSession
();
$session
->
startTransaction
();
...
...
tests/Operation/FindFunctionalTest.php
View file @
45190ee1
...
...
@@ -7,7 +7,6 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\Find
;
use
MongoDB\Tests\CommandObserver
;
use
Exception
;
...
...
@@ -225,9 +224,7 @@ class FindFunctionalTest extends FunctionalTestCase
$this
->
skipIfTransactionsAreNotSupported
();
// Collection must be created before the transaction starts
$options
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
createCollection
();
$session
=
$this
->
manager
->
startSession
();
$session
->
startTransaction
();
...
...
tests/Operation/FunctionalTestCase.php
View file @
45190ee1
...
...
@@ -44,14 +44,4 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
{
return
$this
->
manager
->
startSession
();
}
private
function
dropCollection
()
{
$options
=
version_compare
(
$this
->
getServerVersion
(),
'3.4.0'
,
'>='
)
?
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)]
:
[];
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$options
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
tests/Operation/MapReduceFunctionalTest.php
View file @
45190ee1
...
...
@@ -4,7 +4,6 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\BSON\Javascript
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\Find
;
use
MongoDB\Operation\MapReduce
;
...
...
@@ -15,8 +14,8 @@ class MapReduceFunctionalTest extends FunctionalTestCase
{
public
function
testDefaultReadConcernIsOmitted
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$
operation
->
execute
(
$this
->
getPrimaryServer
()
);
// Collection must exist for mapReduce command
$
this
->
createCollection
(
);
(
new
CommandObserver
)
->
observe
(
function
()
{
...
...
@@ -39,8 +38,8 @@ class MapReduceFunctionalTest extends FunctionalTestCase
public
function
testDefaultWriteConcernIsOmitted
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$
operation
->
execute
(
$this
->
getPrimaryServer
()
);
// Collection must exist for mapReduce command
$
this
->
createCollection
(
);
(
new
CommandObserver
)
->
observe
(
function
()
{
...
...
tests/Operation/ModifyCollectionFunctionalTest.php
View file @
45190ee1
...
...
@@ -3,15 +3,13 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\ModifyCollection
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\CreateIndexes
;
class
ModifyCollectionFunctionalTest
extends
FunctionalTestCase
{
public
function
testCollMod
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
createCollection
();
$indexes
=
[[
'key'
=>
[
'lastAccess'
=>
1
],
'expireAfterSeconds'
=>
3
]];
$createIndexes
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$indexes
);
...
...
tests/Operation/WatchFunctionalTest.php
View file @
45190ee1
...
...
@@ -9,9 +9,7 @@ use MongoDB\Driver\ReadPreference;
use
MongoDB\Driver\Server
;
use
MongoDB\Driver\Exception\ConnectionTimeoutException
;
use
MongoDB\Exception\ResumeTokenException
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Operation\DatabaseCommand
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\Watch
;
use
MongoDB\Tests\CommandObserver
;
...
...
@@ -727,8 +725,8 @@ class WatchFunctionalTest extends FunctionalTestCase
public
function
testSessionFreed
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$
operation
->
execute
(
$this
->
getPrimaryServer
()
);
// Create collection so we can drop it later
$
this
->
createCollection
(
);
$operation
=
new
Watch
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
$this
->
defaultOptions
);
$changeStream
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
...
...
@@ -740,8 +738,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this
->
assertNotNull
(
$rp
->
getValue
(
$changeStream
));
// Invalidate the cursor to verify that resumeCallable is unset when the cursor is exhausted.
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
dropCollection
();
$changeStream
->
next
();
...
...
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