/** * 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); } } }
/** * @covers ::persist * @covers ::loadPersistors * @covers ::doPersist * @covers ::updateConfigOverridedSectionsForSite */ public function test_persistWithConfigPerSite() { $this->application->setIs_Started(true); $this->application->getConfig()->setSection('config', array('persistor' => 'BackBee\\Config\\Tests\\Persistor\\FakePersistor')); $this->application->getConfig()->setSection('parameters', array('hello' => 'foo')); $this->application->setContainer(new Container()); $this->application->getContainer()->set('container.builder', new FakeContainerBuilder()); $current_config = $this->application->getConfig()->getAllRawSections(); $this->application->setSite($site = new Site()); $this->persistor->persist($this->application->getConfig(), true); $this->assertTrue($this->application->getConfig()->getSection('override_site') !== null); $updated_override_section = array('override_site' => array($site->getUid() => array('parameters' => array('hello' => 'foo'), 'config' => array('persistor' => 'BackBee\\Config\\Tests\\Persistor\\FakePersistor')))); $this->assertEquals(array_merge($current_config, $updated_override_section), $this->application->getConfig()->getAllRawSections()); $this->assertEquals(array_merge($this->configurator->getConfigDefaultSections($this->application->getConfig()), $updated_override_section), $this->application->getContainer()->getParameter('config_to_persist')); }
/** * 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()); }
/** * @covers ::getRegistryScope */ public function testGetRegistryScopeWithContextAndEnvironment() { $this->application->setContext('api'); $this->application->setEnvironment('preprod'); $configurator = new Configurator($this->application, $this->bundleLoader); $this->assertEquals('PREFIX.api.preprod', $configurator->getRegistryScope('PREFIX', true, true)); $this->assertEquals('PREFIX.preprod', $configurator->getRegistryScope('PREFIX', false, true)); $this->assertEquals('PREFIX.api', $configurator->getRegistryScope('PREFIX', true, false)); $this->assertEquals('PREFIX', $configurator->getRegistryScope('PREFIX', false, false)); }