Commit 554e73f7 authored by Derick Rethans's avatar Derick Rethans

PHPLIB-352: Only send bypassDocumentValidation if it's true

parent f24bfcd7
...@@ -299,7 +299,10 @@ class Aggregate implements Executable ...@@ -299,7 +299,10 @@ class Aggregate implements Executable
$cmd['allowDiskUse'] = $this->options['allowDiskUse']; $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']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -324,7 +324,10 @@ class BulkWrite implements Executable ...@@ -324,7 +324,10 @@ class BulkWrite implements Executable
$options = ['ordered' => $this->options['ordered']]; $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']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -264,7 +264,10 @@ class FindAndModify implements Executable, Explainable ...@@ -264,7 +264,10 @@ class FindAndModify implements Executable, Explainable
$cmd['maxTimeMS'] = $this->options['maxTimeMS']; $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']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -128,7 +128,10 @@ class InsertMany implements Executable ...@@ -128,7 +128,10 @@ class InsertMany implements Executable
{ {
$options = ['ordered' => $this->options['ordered']]; $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']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -104,7 +104,10 @@ class InsertOne implements Executable ...@@ -104,7 +104,10 @@ class InsertOne implements Executable
{ {
$options = []; $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']; $options['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -291,7 +291,10 @@ class MapReduce implements Executable ...@@ -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']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -169,7 +169,10 @@ class Update implements Executable, Explainable ...@@ -169,7 +169,10 @@ class Update implements Executable, Explainable
$bulkOptions = []; $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']; $bulkOptions['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
...@@ -189,7 +192,10 @@ class Update implements Executable, Explainable ...@@ -189,7 +192,10 @@ class Update implements Executable, Explainable
$cmd['writeConcern'] = $this->options['writeConcern']; $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']; $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
} }
......
...@@ -193,6 +193,45 @@ class AggregateFunctionalTest extends FunctionalTestCase ...@@ -193,6 +193,45 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->assertCollectionCount($this->getCollectionName() . '.output', 0); $this->assertCollectionCount($this->getCollectionName() . '.output', 0);
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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() public function provideTypeMapOptionsAndExpectedDocuments()
{ {
return [ return [
......
...@@ -305,6 +305,45 @@ class BulkWriteFunctionalTest extends FunctionalTestCase ...@@ -305,6 +305,45 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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. * Create data fixtures.
* *
......
...@@ -292,6 +292,59 @@ class ExplainFunctionalTest extends FunctionalTestCase ...@@ -292,6 +292,59 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected); $this->assertExplainResult($result, $executionStatsExpected, $allPlansExecutionExpected);
} }
public function testUpdateBypassDocumentValidationSetWhenTrue()
{
$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()
{
$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 * @dataProvider provideVerbosityInformation
*/ */
......
...@@ -76,6 +76,43 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase ...@@ -76,6 +76,43 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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 * @dataProvider provideTypeMapOptionsAndExpectedDocument
*/ */
......
...@@ -76,6 +76,45 @@ class InsertManyFunctionalTest extends FunctionalTestCase ...@@ -76,6 +76,45 @@ class InsertManyFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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() public function testUnacknowledgedWriteConcern()
{ {
$documents = [['x' => 11]]; $documents = [['x' => 11]];
......
...@@ -91,6 +91,45 @@ class InsertOneFunctionalTest extends FunctionalTestCase ...@@ -91,6 +91,45 @@ class InsertOneFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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() public function testUnacknowledgedWriteConcern()
{ {
$document = ['x' => 11]; $document = ['x' => 11];
......
...@@ -156,6 +156,53 @@ class MapReduceFunctionalTest extends FunctionalTestCase ...@@ -156,6 +156,53 @@ class MapReduceFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
$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()
{
$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 * @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/ */
......
...@@ -46,6 +46,47 @@ class UpdateFunctionalTest extends FunctionalTestCase ...@@ -46,6 +46,47 @@ class UpdateFunctionalTest extends FunctionalTestCase
); );
} }
public function testBypassDocumentValidationSetWhenTrue()
{
(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()
{
(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() public function testUpdateOne()
{ {
$this->createFixtures(3); $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