I found a solution that could work based on JMSSecurityBundle .
Instead of checking the configuration, I am testing an extension, which, by the way, will add coverage for the configuration. That way, I can claim that the default setting has been set.
For example, this is Extension .
#My\Bundle\DependencyInjection\MyBundleExtension class MyBundleExtension extends Extension { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $container->setParameter("crak_landing_frontend.scalar", $config["scalar"]); $container->setParameter("crak_landing_frontend.array_node", $config["array_node"]); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); } }
There may be tests such as:
#My\Bundle\Tests\DependencyInjection\MyBundleExtensionTest class MyBundleExtensionTest extends \PHPUnit_Framework_TestCase { private $extension; private $root; public function setUp() { parent::setUp(); $this->extension = $this->getExtension(); $this->root = "my_bundle"; } public function testGetConfigWithDefaultValues() { $this->extension->load(array(), $container = $this->getContainer()); $this->assertTrue($container->hasParameter($this->root . ".scalar")); $this->assertEquals("defaultValue", $container->getParameter($this->root . ".scalar")); $expected = array( "val1" => "defaultValue1", "val2" => "defaultValue2", ); $this->assertTrue($container->hasParameter($this->root . ".array_node")); $this->assertEquals($expected, $container->getParameter($this->root . ".array_node")); } public function testGetConfigWithOverrideValues() { $configs = array( "scalar" => "scalarValue", "array_node" => array( "val1" => "array_value_1", "val2" => "array_value_2", ), ); $this->extension->load(array($configs), $container = $this->getContainer()); $this->assertTrue($container->hasParameter($this->root . ".scalar")); $this->assertEquals("scalarValue", $container->getParameter($this->root . ".scalar")); $expected = array( "val1" => "array_value_1", "val2" => "array_value_2", ); $this->assertTrue($container->hasParameter($this->root . ".array_node")); $this->assertEquals($expected, $container->getParameter($this->root . ".array_node")); } protected function getExtension() { return new MyBundleExtension(); } private function getContainer() { $container = new ContainerBuilder(); return $container; } }
source share