/** * {@inheritdoc} */ public function writeConfigFile(ConfigFile $configFile, $path) { $jsonData = new stdClass(); foreach ($configFile->getConfig()->toRawArray(false) as $key => $value) { $jsonData->{$key} = $value; } $this->encodeFile($jsonData, $path); }
public function testWriteConfig() { $configFile = new ConfigFile(); $configFile->getConfig()->merge(array(Config::PULI_DIR => 'puli-dir', Config::FACTORY_OUT_CLASS => 'Puli\\MyFactory', Config::FACTORY_OUT_FILE => '{$puli-dir}/MyFactory.php', Config::REPOSITORY_TYPE => 'my-type', Config::REPOSITORY_PATH => '{$puli-dir}/my-repo', Config::DISCOVERY_STORE_TYPE => 'my-store-type')); $this->writer->writeConfigFile($configFile, $this->tempFile); $this->assertFileExists($this->tempFile); $this->assertJsonFileEquals(__DIR__ . '/Fixtures/config.json', $this->tempFile); }
public function testBaseConfig() { $baseConfig = new Config(); $configFile = new ConfigFile('/path', $baseConfig); $config = $configFile->getConfig(); $this->assertNotSame($baseConfig, $config); $baseConfig->set(Config::PULI_DIR, 'my-puli-dir'); $this->assertSame('my-puli-dir', $config->get(Config::PULI_DIR)); $this->assertNull($config->get(Config::PULI_DIR, null, false)); }
/** * {@inheritdoc} */ public function unserializeConfigFile($serialized, $path = null, Config $baseConfig = null) { $configFile = new ConfigFile($path, $baseConfig); $config = $configFile->getConfig(); $jsonData = $this->objectsToArrays($this->decode($serialized, $path)); foreach ($jsonData as $key => $value) { $config->set($key, $value); } return $configFile; }
/** * {@inheritdoc} */ public function fromJson($jsonData, array $options = array()) { $path = isset($options['path']) ? $options['path'] : null; $baseConfig = isset($options['baseConfig']) ? $options['baseConfig'] : null; Assert::isInstanceOf($jsonData, 'stdClass'); Assert::nullOrString($path, 'The "path" option should be null or a string. Got: %s'); Assert::nullOrIsInstanceOf($baseConfig, 'Puli\\Manager\\Api\\Config\\Config', 'The "baseConfig" option should be null or an instance of %2$s. Got: %s'); $configFile = new ConfigFile($path, $baseConfig); $config = $configFile->getConfig(); $jsonData = $this->objectsToArrays($jsonData); foreach ($jsonData as $key => $value) { $config->set($key, $value); } return $configFile; }
public function testClearConfigKeysRevertsIfSavingNotPossible() { $this->configFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir'); $this->configFileStorage->expects($this->once())->method('saveConfigFile')->willThrowException(new TestException()); try { $this->manager->clearConfigKeys(); $this->fail('Expected a TestException'); } catch (TestException $e) { } $this->assertTrue($this->configFile->getConfig()->contains(Config::PULI_DIR)); $this->assertFalse($this->configFile->getConfig()->contains(Config::FACTORY_IN_FILE)); $this->assertSame('my-puli-dir', $this->configFile->getConfig()->get(Config::PULI_DIR)); }
/** * {@inheritdoc} */ public function getConfig() { return $this->configFile->getConfig(); }