Commit b6320a09 authored by Derick Rethans's avatar Derick Rethans

Merged pull request #586

parents f24bfcd7 2ec8ccfd
......@@ -299,7 +299,10 @@ class Aggregate implements Executable
$cmd['allowDiskUse'] = $this->options['allowDiskUse'];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -324,7 +324,10 @@ class BulkWrite implements Executable
$options = ['ordered' => $this->options['ordered']];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -264,7 +264,10 @@ class FindAndModify implements Executable, Explainable
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -128,7 +128,10 @@ class InsertMany implements Executable
{
$options = ['ordered' => $this->options['ordered']];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -104,7 +104,10 @@ class InsertOne implements Executable
{
$options = [];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -291,7 +291,10 @@ class MapReduce implements Executable
}
}
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -169,7 +169,10 @@ class Update implements Executable, Explainable
$bulkOptions = [];
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$bulkOptions['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......@@ -189,7 +192,10 @@ class Update implements Executable, Explainable
$cmd['writeConcern'] = $this->options['writeConcern'];
}
if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) {
if (
! empty($this->options['bypassDocumentValidation']) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
) {
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
......
......@@ -193,6 +193,53 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->assertCollectionCount($this->getCollectionName() . '.output', 0);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new Aggregate(
$this->getDatabaseName(),
$this->getCollectionName(),
[['$match' => ['x' => 1]]],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new Aggregate(
$this->getDatabaseName(),
$this->getCollectionName(),
[['$match' => ['x' => 1]]],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
public function provideTypeMapOptionsAndExpectedDocuments()
{
return [
......
......@@ -305,6 +305,53 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new BulkWrite(
$this->getDatabaseName(),
$this->getCollectionName(),
[['insertOne' => [['_id' => 1]]]],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new BulkWrite(
$this->getDatabaseName(),
$this->getCollectionName(),
[['insertOne' => [['_id' => 1]]]],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
/**
* Create data fixtures.
*
......
......@@ -292,6 +292,67 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected);
}
public function testUpdateBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
$this->createFixtures(3);
(new CommandObserver)->observe(
function() {
$operation = new Update(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => ['$gt' => 1]],
['$inc' => ['x' => 1]],
['bypassDocumentValidation' => true]
);
$explainOperation = new Explain($this->getDatabaseName(), $operation);
$result = $explainOperation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute(
'bypassDocumentValidation',
$event['started']->getCommand()->explain
);
$this->assertEquals(true, $event['started']->getCommand()->explain->bypassDocumentValidation);
}
);
}
public function testUpdateBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
$this->createFixtures(3);
(new CommandObserver)->observe(
function() {
$operation = new Update(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => ['$gt' => 1]],
['$inc' => ['x' => 1]],
['bypassDocumentValidation' => false]
);
$explainOperation = new Explain($this->getDatabaseName(), $operation);
$result = $explainOperation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute(
'bypassDocumentValidation',
$event['started']->getCommand()->explain
);
}
);
}
/**
* @dataProvider provideVerbosityInformation
*/
......
......@@ -76,6 +76,51 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new FindAndModify(
$this->getDatabaseName(),
$this->getCollectionName(),
['remove' => true, 'bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new FindAndModify(
$this->getDatabaseName(),
$this->getCollectionName(),
['remove' => true, 'bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocument
*/
......
......@@ -76,6 +76,53 @@ class InsertManyFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new InsertMany(
$this->getDatabaseName(),
$this->getCollectionName(),
[['_id' => 1], ['_id' => 2]],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new InsertMany(
$this->getDatabaseName(),
$this->getCollectionName(),
[['_id' => 1], ['_id' => 2]],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
public function testUnacknowledgedWriteConcern()
{
$documents = [['x' => 11]];
......
......@@ -91,6 +91,53 @@ class InsertOneFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new InsertOne(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => 1],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new InsertOne(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => 1],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
public function testUnacknowledgedWriteConcern()
{
$document = ['x' => 11];
......
......@@ -156,6 +156,61 @@ class MapReduceFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
$this->createFixtures(1);
(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],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
$this->createFixtures(1);
(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],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
......
......@@ -46,6 +46,55 @@ class UpdateFunctionalTest extends FunctionalTestCase
);
}
public function testBypassDocumentValidationSetWhenTrue()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new Update(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => 1],
['$inc' => ['x' => 1]],
['bypassDocumentValidation' => true]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
$this->assertEquals(true, $event['started']->getCommand()->bypassDocumentValidation);
}
);
}
public function testBypassDocumentValidationUnsetWhenFalse()
{
if (version_compare($this->getServerVersion(), '3.2.0', '<')) {
$this->markTestSkipped('bypassDocumentValidation is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new Update(
$this->getDatabaseName(),
$this->getCollectionName(),
['_id' => 1],
['$inc' => ['x' => 1]],
['bypassDocumentValidation' => false]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertObjectNotHasAttribute('bypassDocumentValidation', $event['started']->getCommand());
}
);
}
public function testUpdateOne()
{
$this->createFixtures(3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment