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
236657b5
Commit
236657b5
authored
Aug 29, 2017
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-261: Omit default read and write concern from commands
parent
6e091545
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
445 additions
and
0 deletions
+445
-0
Aggregate.php
src/Operation/Aggregate.php
+8
-0
BulkWrite.php
src/Operation/BulkWrite.php
+4
-0
Count.php
src/Operation/Count.php
+4
-0
CreateCollection.php
src/Operation/CreateCollection.php
+4
-0
CreateIndexes.php
src/Operation/CreateIndexes.php
+4
-0
Delete.php
src/Operation/Delete.php
+4
-0
Distinct.php
src/Operation/Distinct.php
+4
-0
DropCollection.php
src/Operation/DropCollection.php
+4
-0
DropDatabase.php
src/Operation/DropDatabase.php
+4
-0
DropIndexes.php
src/Operation/DropIndexes.php
+4
-0
Find.php
src/Operation/Find.php
+4
-0
FindAndModify.php
src/Operation/FindAndModify.php
+4
-0
InsertMany.php
src/Operation/InsertMany.php
+4
-0
InsertOne.php
src/Operation/InsertOne.php
+4
-0
MapReduce.php
src/Operation/MapReduce.php
+8
-0
Update.php
src/Operation/Update.php
+4
-0
CommandObserver.php
tests/CommandObserver.php
+44
-0
AggregateFunctionalTest.php
tests/Operation/AggregateFunctionalTest.php
+44
-0
CountFunctionalTest.php
tests/Operation/CountFunctionalTest.php
+29
-0
CreateCollectionFunctionalTest.php
tests/Operation/CreateCollectionFunctionalTest.php
+28
-0
CreateIndexesFunctionalTest.php
tests/Operation/CreateIndexesFunctionalTest.php
+28
-0
DistinctFunctionalTest.php
tests/Operation/DistinctFunctionalTest.php
+30
-0
DropCollectionFunctionalTest.php
tests/Operation/DropCollectionFunctionalTest.php
+20
-0
DropDatabaseFunctionalTest.php
tests/Operation/DropDatabaseFunctionalTest.php
+19
-0
DropIndexesFunctionalTest.php
tests/Operation/DropIndexesFunctionalTest.php
+24
-0
FindAndModifyFunctionalTest.php
tests/Operation/FindAndModifyFunctionalTest.php
+20
-0
FindFunctionalTest.php
tests/Operation/FindFunctionalTest.php
+21
-0
FunctionalTestCase.php
tests/Operation/FunctionalTestCase.php
+12
-0
MapReduceFunctionalTest.php
tests/Operation/MapReduceFunctionalTest.php
+54
-0
No files found.
src/Operation/Aggregate.php
View file @
236657b5
...
...
@@ -182,6 +182,14 @@ class Aggregate implements Executable
throw
new
InvalidArgumentException
(
'"typeMap" option should not be used if "useCursor" is false'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
pipeline
=
$pipeline
;
...
...
src/Operation/BulkWrite.php
View file @
236657b5
...
...
@@ -266,6 +266,10 @@ class BulkWrite implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
operations
=
$operations
;
...
...
src/Operation/Count.php
View file @
236657b5
...
...
@@ -117,6 +117,10 @@ class Count implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"skip" option'
,
$options
[
'skip'
],
'integer'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
filter
=
$filter
;
...
...
src/Operation/CreateCollection.php
View file @
236657b5
...
...
@@ -157,6 +157,10 @@ class CreateCollection implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
options
=
$options
;
...
...
src/Operation/CreateIndexes.php
View file @
236657b5
...
...
@@ -96,6 +96,10 @@ class CreateIndexes implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
options
=
$options
;
...
...
src/Operation/Delete.php
View file @
236657b5
...
...
@@ -83,6 +83,10 @@ class Delete implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
filter
=
$filter
;
...
...
src/Operation/Distinct.php
View file @
236657b5
...
...
@@ -93,6 +93,10 @@ class Distinct implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"readPreference" option'
,
$options
[
'readPreference'
],
'MongoDB\Driver\ReadPreference'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
fieldName
=
(
string
)
$fieldName
;
...
...
src/Operation/DropCollection.php
View file @
236657b5
...
...
@@ -69,6 +69,10 @@ class DropCollection implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
options
=
$options
;
...
...
src/Operation/DropDatabase.php
View file @
236657b5
...
...
@@ -66,6 +66,10 @@ class DropDatabase implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
options
=
$options
;
}
...
...
src/Operation/DropIndexes.php
View file @
236657b5
...
...
@@ -75,6 +75,10 @@ class DropIndexes implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
indexName
=
$indexName
;
...
...
src/Operation/Find.php
View file @
236657b5
...
...
@@ -190,6 +190,10 @@ class Find implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"typeMap" option'
,
$options
[
'typeMap'
],
'array'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
filter
=
$filter
;
...
...
src/Operation/FindAndModify.php
View file @
236657b5
...
...
@@ -157,6 +157,10 @@ class FindAndModify implements Executable
throw
new
InvalidArgumentException
(
'The "remove" option must be true or an "update" document must be specified, but not both'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
options
=
$options
;
...
...
src/Operation/InsertMany.php
View file @
236657b5
...
...
@@ -97,6 +97,10 @@ class InsertMany implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
documents
=
$documents
;
...
...
src/Operation/InsertOne.php
View file @
236657b5
...
...
@@ -73,6 +73,10 @@ class InsertOne implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
document
=
$document
;
...
...
src/Operation/MapReduce.php
View file @
236657b5
...
...
@@ -203,6 +203,14 @@ class MapReduce implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
map
=
$map
;
...
...
src/Operation/Update.php
View file @
236657b5
...
...
@@ -117,6 +117,10 @@ class Update implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
if
(
isset
(
$options
[
'writeConcern'
])
&&
$options
[
'writeConcern'
]
->
isDefault
())
{
unset
(
$options
[
'writeConcern'
]);
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
filter
=
$filter
;
...
...
tests/CommandObserver.php
0 → 100644
View file @
236657b5
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Driver\Monitoring\CommandFailedEvent
;
use
MongoDB\Driver\Monitoring\CommandStartedEvent
;
use
MongoDB\Driver\Monitoring\CommandSucceededEvent
;
use
MongoDB\Driver\Monitoring\CommandSubscriber
;
/**
* Observes command documents using the driver's monitoring API.
*/
class
CommandObserver
implements
CommandSubscriber
{
private
$commands
=
[];
public
function
observe
(
callable
$execution
,
callable
$commandCallback
)
{
$this
->
commands
=
[];
\MongoDB\Driver\Monitoring\addSubscriber
(
$this
);
call_user_func
(
$execution
);
\MongoDB\Driver\Monitoring\removeSubscriber
(
$this
);
foreach
(
$this
->
commands
as
$command
)
{
call_user_func
(
$commandCallback
,
$command
);
}
}
public
function
commandStarted
(
CommandStartedEvent
$event
)
{
$this
->
commands
[]
=
$event
->
getCommand
();
}
public
function
commandSucceeded
(
CommandSucceededEvent
$event
)
{
}
public
function
commandFailed
(
CommandFailedEvent
$event
)
{
}
}
tests/Operation/AggregateFunctionalTest.php
View file @
236657b5
...
...
@@ -4,11 +4,55 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Operation\Aggregate
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
AggregateFunctionalTest
extends
FunctionalTestCase
{
private
static
$wireVersionForCursor
=
2
;
public
function
testDefaultReadConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$match'
=>
[
'x'
=>
1
]]],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'readConcern'
,
$command
);
}
);
}
public
function
testDefaultWriteConcernIsOmitted
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'2.6.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'$out pipeline operator is not supported'
);
}
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$out'
=>
$this
->
getCollectionName
()
.
'.output'
]],
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
/**
* @expectedException MongoDB\Driver\Exception\RuntimeException
*/
...
...
tests/Operation/CountFunctionalTest.php
0 → 100644
View file @
236657b5
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Count
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
CountFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultReadConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Count
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'readConcern'
,
$command
);
}
);
}
}
tests/Operation/CreateCollectionFunctionalTest.php
0 → 100644
View file @
236657b5
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\CreateCollection
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
CreateCollectionFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultWriteConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
}
tests/Operation/CreateIndexesFunctionalTest.php
View file @
236657b5
...
...
@@ -6,7 +6,9 @@ use MongoDB\Model\IndexInfo;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropIndexes
;
use
MongoDB\Operation\ListIndexes
;
use
MongoDB\Tests\CommandObserver
;
use
InvalidArgumentException
;
use
stdClass
;
class
CreateIndexesFunctionalTest
extends
FunctionalTestCase
{
...
...
@@ -157,6 +159,32 @@ class CreateIndexesFunctionalTest extends FunctionalTestCase
});
}
public
function
testDefaultWriteConcernIsOmitted
()
{
/* Earlier server versions do not support the createIndexes command. Per
* the Index Management specification, inserts on system.indexes must
* use the write concern {w:1}. */
if
(
version_compare
(
$this
->
getServerVersion
(),
'2.6.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'createIndexes command is not supported'
);
}
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'key'
=>
[
'x'
=>
1
]]],
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
/**
* Asserts that an index with the given name exists for the collection.
*
...
...
tests/Operation/DistinctFunctionalTest.php
0 → 100644
View file @
236657b5
<?php
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Operation\Distinct
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
DistinctFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultReadConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Distinct
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x'
,
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'readConcern'
,
$command
);
}
);
}
}
tests/Operation/DropCollectionFunctionalTest.php
View file @
236657b5
...
...
@@ -5,9 +5,29 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\ListCollections
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
DropCollectionFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultWriteConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
public
function
testDropExistingCollection
()
{
$server
=
$this
->
getPrimaryServer
();
...
...
tests/Operation/DropDatabaseFunctionalTest.php
View file @
236657b5
...
...
@@ -6,9 +6,28 @@ use MongoDB\Driver\Server;
use
MongoDB\Operation\DropDatabase
;
use
MongoDB\Operation\InsertOne
;
use
MongoDB\Operation\ListDatabases
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
DropDatabaseFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultWriteConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
DropDatabase
(
$this
->
getDatabaseName
(),
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
public
function
testDropExistingDatabase
()
{
$server
=
$this
->
getPrimaryServer
();
...
...
tests/Operation/DropIndexesFunctionalTest.php
View file @
236657b5
...
...
@@ -5,10 +5,34 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropIndexes
;
use
MongoDB\Operation\ListIndexes
;
use
MongoDB\Tests\CommandObserver
;
use
InvalidArgumentException
;
use
stdClass
;
class
DropIndexesFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultWriteConcernIsOmitted
()
{
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'key'
=>
[
'x'
=>
1
]]]);
$operation
->
execute
(
$this
->
getPrimaryServer
());
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
DropIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
'x_1'
,
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
public
function
testDropOneIndexByName
()
{
$indexes
=
[[
'key'
=>
[
'x'
=>
1
]]];
...
...
tests/Operation/FindAndModifyFunctionalTest.php
View file @
236657b5
...
...
@@ -5,9 +5,29 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Model\BSONDocument
;
use
MongoDB\Operation\FindAndModify
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
FindAndModifyFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultWriteConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
,
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocument
*/
...
...
tests/Operation/FindFunctionalTest.php
View file @
236657b5
...
...
@@ -4,9 +4,30 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Operation\Find
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
FindFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultReadConcernIsOmitted
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Find
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'readConcern'
,
$command
);
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
...
...
tests/Operation/FunctionalTestCase.php
View file @
236657b5
...
...
@@ -3,7 +3,9 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Collection
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Operation\DropCollection
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
...
...
@@ -29,4 +31,14 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
protected
function
createDefaultReadConcern
()
{
return
new
ReadConcern
;
}
protected
function
createDefaultWriteConcern
()
{
return
new
WriteConcern
(
-
2
);
}
}
tests/Operation/MapReduceFunctionalTest.php
View file @
236657b5
...
...
@@ -4,12 +4,66 @@ 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
;
use
MongoDB\Tests\CommandObserver
;
use
stdClass
;
class
MapReduceFunctionalTest
extends
FunctionalTestCase
{
public
function
testDefaultReadConcernIsOmitted
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
MapReduce
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
new
Javascript
(
'function() { emit(this.x, this.y); }'
),
new
Javascript
(
'function(key, values) { return Array.sum(values); }'
),
[
'inline'
=>
1
],
[
'readConcern'
=>
$this
->
createDefaultReadConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'readConcern'
,
$command
);
}
);
}
public
function
testDefaultWriteConcernIsOmitted
()
{
$operation
=
new
CreateCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
MapReduce
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
new
Javascript
(
'function() { emit(this.x, this.y); }'
),
new
Javascript
(
'function(key, values) { return Array.sum(values); }'
),
$this
->
getCollectionName
()
.
'.output'
,
[
'writeConcern'
=>
$this
->
createDefaultWriteConcern
()]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
stdClass
$command
)
{
$this
->
assertObjectNotHasAttribute
(
'writeConcern'
,
$command
);
}
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
()
.
'.output'
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
public
function
testResult
()
{
$this
->
createFixtures
(
3
);
...
...
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