Skip to content

Commit 991b3a2

Browse files
committed
Merge pull request #330 from alcaeus/validate-replicaset-string
Add validation to ensure replicaSet is a string
2 parents 66b3019 + acc2ba5 commit 991b3a2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode)
232232
->prototype('scalar')->end()
233233
->end()
234234
->end()
235-
->scalarNode('replicaSet')->end()
235+
->scalarNode('replicaSet')
236+
->validate()->ifTrue(function ($v) { return !is_string($v); })->thenInvalid('The replicaSet option must be a string')->end()
237+
->end()
236238
->scalarNode('socketTimeoutMS')->end()
237239
->booleanNode('ssl')->end()
238240
->scalarNode('username')

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,26 @@ public function testPasswordAndUsernameShouldBeUnsetIfNull()
412412
$this->assertEquals(array('username' => 'foo'), $options['connections']['conn2']['options']);
413413
$this->assertEquals(array(), $options['connections']['conn3']['options']);
414414
}
415+
416+
/**
417+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
418+
* @expectedExceptionMessage The replicaSet option must be a string
419+
*/
420+
public function testInvalidReplicaSetValue()
421+
{
422+
$config = array(
423+
'connections' => array(
424+
'conn1' => array(
425+
'server' => 'mongodb://localhost',
426+
'options' => array(
427+
'replicaSet' => true
428+
)
429+
)
430+
)
431+
);
432+
433+
$processor = new Processor();
434+
$configuration = new Configuration(false);
435+
$processor->processConfiguration($configuration, array($config));
436+
}
415437
}

0 commit comments

Comments
 (0)