[SecurityBundle] Allowing the main Configuration tree to allow "factories" without a validation exception.

The main tree doesn't actually process the factories (that's done in an earlier step), so it doesn't actually need their real value. It does, however, need to *not* throw an exception when they're present. An alternative to this approach would be to call ignoreExtraKeys() on the root node of the main tree, but this would allow extra keys to be passed in at the root level, which I thought was a less-desirable solution.
This commit is contained in:
Ryan Weaver 2011-02-18 16:12:12 -06:00
parent b20ee0fb71
commit c9406b62b2
2 changed files with 59 additions and 0 deletions

View File

@ -40,6 +40,12 @@ class Configuration
$rootNode
->scalarNode('access_denied_url')->defaultNull()->end()
->scalarNode('session_fixation_strategy')->cannotBeEmpty()->defaultValue('migrate')->end()
// add a faux-entry for factories, so that no validation error is thrown
->fixXmlConfig('factory', 'factories')
->arrayNode('factories')
->ignoreExtraKeys()
->end()
;
$this->addAclSection($rootNode);

View File

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* The minimal, required config needed to not have any required validation
* issues.
*
* @var array
*/
protected static $minimalConfig = array(
'providers' => array(
'stub' => array(),
),
'firewalls' => array(
'stub' => array(),
),
);
/**
* Test that the main tree is OK to be passed a factory or factories
* key, without throwing any validation errors.
*/
public function testMainConfigTreeWithFactories()
{
$config = array_merge(self::$minimalConfig, array(
'factory' => array('foo' => 'bar'),
'factories' => array('lorem' => 'ipsum'),
));
$configuration = new Configuration();
$processor = new Processor();
$tree = $configuration->getMainConfigTree(array());
$config = $processor->process($tree, array($config));
$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 jsut an empty array');
}
}