Permalink
Browse files

Allow valid write concern options for "safe" (fixes #163)

Currently, the "safe" option is also used for write concerns, so we should also allow strings. Additionally, the lower bound for acceptable integers should be -1. This will likely change later when we support an explicit "w" option.
  • Loading branch information...
1 parent 00568cc commit a2deb252a3d4de09d5512cb5af6121468a17a2ae @jmikola jmikola committed Mar 18, 2013
Showing with 28 additions and 4 deletions.
  1. +2 −2 DependencyInjection/Configuration.php
  2. +26 −2 Tests/DependencyInjection/ConfigurationTest.php
@@ -59,8 +59,8 @@ public function getConfigTreeBuilder()
->then(function($v) { return (int) $v; })
->end()
->validate()
- ->ifTrue(function($v) { return !(is_bool($v) || (is_int($v) && $v > 0)); })
- ->thenInvalid('Boolean or positive integer expected for "safe" commit option')
+ ->ifTrue(function($v) { return !(is_scalar($v) && (!is_int($v) || $v >= -1)); })
stof
stof Mar 18, 2013 Member

is_scalar is useless here. It is already validated as it is a scalarNode

jmikola
jmikola Mar 18, 2013 Owner

Thanks. Fixed in b7b9ff9

+ ->thenInvalid('Scalar expected for "safe" commit option')
->end()
->end()
->booleanNode('fsync')->defaultFalse()->end()
@@ -329,6 +329,29 @@ public function getNormalizationTests()
}
/**
+ * @dataProvider getValidSafeCommitOptions
+ */
+ public function testValidSafeCommitOptions($safeCommitOption)
+ {
+ $invalidConfig = array('default_commit_options' => array('safe' => $safeCommitOption));
+
+ $processor = new Processor();
+ $configuration = new Configuration(false);
+ $options = $processor->processConfiguration($configuration, array($invalidConfig));
+ }
+
+ public function getValidSafeCommitOptions()
+ {
+ return array(
+ array(0),
+ array(1),
+ array(true),
+ array('majority'),
+ array(-1),
+ );
+ }
+
+ /**
* @dataProvider getInvalidSafeCommitOptions
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
@@ -344,8 +367,9 @@ public function testInvalidSafeCommitOptions($safeCommitOption)
public function getInvalidSafeCommitOptions()
{
return array(
- array('NaN'),
- array(-1.0),
+ array(array()),
+ array(new \stdClass()),
+ array(-2),
);
}

0 comments on commit a2deb25

Please sign in to comment.