/** * Do every extend according to application context, environment and config target type (APPLICATION OR BUNDLE). * * @param integer $type define which kind of extend we want to apply * (self::APPLICATION_CONFIG or self::BUNDLE_CONFIG) * @param Config $config the config we want to extend * @param array $options options for extend config action */ public function extend($type, Config $config, $options = array()) { if (false === $config->isRestored()) { if (self::APPLICATION_CONFIG === $type) { return parent::extend($type, $config, $options); } elseif (self::BUNDLE_CONFIG === $type) { // do nothing } else { throw new InvalidConfigTypeException('extend', $type); } } }
/** * test extend application config with and without context and environment. * * @covers ::__construct * @covers ::extend * @covers ::doApplicationConfigExtend */ public function testExtendApplicationConfig() { $this->application->setBB_Dir(__DIR__ . '/ConfiguratorTest_Resources/bbdir'); $this->application->setBase_Repository(__DIR__ . '/ConfiguratorTest_Resources/repository'); $this->application->setOverrided_Config(false); // Test without context and without environment $config = new Config($this->application->getBBDir()); $this->assertEquals(array('parameters' => array('base_directory' => 'bbdir', 'context' => 'default', 'environment' => '')), $config->getAllSections()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'default', 'environment' => '', 'foo' => 'bar')), $config->getAllSections()); // Test with context and without environment $this->application->setContext('api'); $config = new Config($this->application->getBBDir()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('base_directory' => 'repository', 'context' => 'api', 'environment' => '', 'foo' => 'bar', 'bar' => 'foo')), $config->getAllSections()); // Test with context and with environment; test also with override config setted at true $this->application->setContext('api'); $this->application->setEnvironment('preprod'); $this->application->setOverrided_Config(true); $config = new Config($this->application->getBBDir()); $config_builder = new Configurator($this->application, $this->bundleLoader); $config_builder->extend(Configurator::APPLICATION_CONFIG, $config); $this->assertEquals(array('parameters' => array('context' => 'api', 'environment' => 'preprod', 'overrided_config' => true)), $config->getAllSections()); }