[SecurityBundle] Added a validation rule

This enforces to configure each provider in exactly one way.
This commit is contained in:
Christophe Coevoet 2011-11-11 23:02:41 +01:00
parent b107a3fdf0
commit 9e41ff4db5
2 changed files with 39 additions and 4 deletions

View File

@ -325,8 +325,7 @@ class MainConfiguration implements ConfigurationInterface
$factory->addConfiguration($factoryNode);
}
/*
* TODO find a way to do the validation. Issue appears because of prototyped nodes
$providerNodeBuilder
->validate()
->ifTrue(function($v){return count($v) > 1;})
@ -337,7 +336,6 @@ class MainConfiguration implements ConfigurationInterface
->thenInvalid('You must set a provider definition for the provider.')
->end()
;
*/
}
private function addEncodersSection(ArrayNodeDefinition $rootNode)

View File

@ -24,7 +24,9 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
*/
protected static $minimalConfig = array(
'providers' => array(
'stub' => array(),
'stub' => array(
'id' => 'foo',
),
),
'firewalls' => array(
'stub' => array(),
@ -49,4 +51,39 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertFalse(array_key_exists('factory', $config), 'The factory key is silently removed without an exception');
$this->assertEquals(array(), $config['factories'], 'The factories key is just an empty array');
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testNoConfigForProvider()
{
$config = array(
'providers' => array(
'stub' => array(),
),
);
$processor = new Processor();
$configuration = new MainConfiguration(array(), array());
$config = $processor->processConfiguration($configuration, array($config));
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function testManyConfigForProvider()
{
$config = array(
'providers' => array(
'stub' => array(
'id' => 'foo',
'chain' => array(),
),
),
);
$processor = new Processor();
$configuration = new MainConfiguration(array(), array());
$config = $processor->processConfiguration($configuration, array($config));
}
}