Skip to content

Commit

Permalink
Merge pull request #330 from alcaeus/validate-replicaset-string
Browse files Browse the repository at this point in the history
Add validation to ensure replicaSet is a string
  • Loading branch information
alcaeus committed Dec 25, 2015
2 parents 66b3019 + acc2ba5 commit 991b3a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->end()
->end()
->scalarNode('replicaSet')->end()
->scalarNode('replicaSet')
->validate()->ifTrue(function ($v) { return !is_string($v); })->thenInvalid('The replicaSet option must be a string')->end()
->end()
->scalarNode('socketTimeoutMS')->end()
->booleanNode('ssl')->end()
->scalarNode('username')
Expand Down
22 changes: 22 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,26 @@ public function testPasswordAndUsernameShouldBeUnsetIfNull()
$this->assertEquals(array('username' => 'foo'), $options['connections']['conn2']['options']);
$this->assertEquals(array(), $options['connections']['conn3']['options']);
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage The replicaSet option must be a string
*/
public function testInvalidReplicaSetValue()
{
$config = array(
'connections' => array(
'conn1' => array(
'server' => 'mongodb://localhost',
'options' => array(
'replicaSet' => true
)
)
)
);

$processor = new Processor();
$configuration = new Configuration(false);
$processor->processConfiguration($configuration, array($config));
}
}

0 comments on commit 991b3a2

Please sign in to comment.