Example #1
0
 /**
  * Update data in the configuration file using specified segment object
  *
  * @param SegmentInterface $segment
  * @return void
  */
 public function update(SegmentInterface $segment)
 {
     $key = $segment->getKey();
     $data = $this->reader->load();
     $data[$key] = $segment->getData();
     $this->write($data);
 }
 /**
  * Checks if deployment configuration has been changed by a test
  *
  * Changing deployment configuration violates isolation between tests, so further tests may become broken.
  * To fix this issue, find out why this test changes deployment configuration.
  * If this is intentional, then it must be reverted to the previous state within the test.
  * After that, the application needs to be wiped out and reinstalled.
  *
  * @param \PHPUnit_Framework_TestCase $test
  * @return void
  */
 public function endTest(\PHPUnit_Framework_TestCase $test)
 {
     $config = $this->reader->load();
     if ($this->config != $config) {
         $error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid.\n" . 'Further tests may fail.' . " This test failure may be misleading, if you are re-running it on a corrupted application.\n" . $test->toString() . "\n";
         $test->fail($error);
     }
 }
Example #3
0
 /**
  * Saves config
  *
  * @param array $data
  * @param bool $override
  * @return void
  */
 public function saveConfig(array $data, $override = false)
 {
     $paths = $this->configFilePool->getPaths();
     foreach ($data as $fileKey => $config) {
         if (isset($paths[$fileKey])) {
             if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
                 $currentData = $this->reader->load($fileKey);
                 if ($override) {
                     $config = array_merge($currentData, $config);
                 } else {
                     $config = array_replace_recursive($currentData, $config);
                 }
             }
             $contents = $this->formatter->format($config);
             try {
                 $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
             } catch (FileSystemException $e) {
                 throw new FileSystemException(new Phrase('Deployment config file %1 is not writable.', [$paths[$fileKey]]));
             }
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($this->filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath($paths[$fileKey]));
             }
         }
     }
     $this->deploymentConfig->resetData();
 }
 /**
  * Loads the configuration data
  *
  * @return void
  */
 private function load()
 {
     if (null === $this->data) {
         $this->data = $this->reader->load();
         if ($this->overrideData) {
             $this->data = array_replace($this->data, $this->overrideData);
         }
         // flatten data for config retrieval using get()
         $this->flatData = $this->flattenParams($this->data);
     }
 }
Example #5
0
 /**
  * Saves config
  *
  * @param array $data
  * @param bool $override
  * @return void
  */
 public function saveConfig(array $data, $override = false)
 {
     $paths = $this->configFilePool->getPaths();
     foreach ($data as $fileKey => $config) {
         if (isset($paths[$fileKey])) {
             if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
                 $currentData = $this->reader->load($paths[$fileKey]);
                 if ($override) {
                     $config = array_merge($currentData, $config);
                 } else {
                     $config = array_replace_recursive($currentData, $config);
                 }
             }
             $contents = $this->formatter->format($config);
             $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
         }
     }
     $this->deploymentConfig->resetData();
 }
Example #6
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Key collision
  */
 public function testMergingWithDuplicateEndValues()
 {
     $configFilePool = $this->getMock('Magento\\Framework\\Config\\File\\ConfigFilePool', [], [], '', false);
     $files = [['configKeyOne', 'config.php'], ['configKeyTwo', 'duplicateConfig.php']];
     $configFilePool->expects($this->any())->method('getPath')->will($this->returnValueMap($files));
     $configFilePool->expects($this->any())->method('getPaths')->willReturn(['configKeyOne' => 'config.php', 'configKeyTwo' => 'duplicateConfig.php']);
     $object = new Reader($this->dirList, $this->driverPool, $configFilePool);
     $object->load();
 }
Example #7
0
 /**
  * Get current mode information
  *
  * @return string
  * @throws \Exception
  */
 public function getMode()
 {
     $env = $this->reader->load(ConfigFilePool::APP_ENV);
     return isset($env[State::PARAM_MODE]) ? $env[State::PARAM_MODE] : null;
 }
 /**
  * Creates modules deployment configuration segment
  *
  * @param \ArrayObject|array $request
  * @param bool $dryRun
  * @return array
  * @throws \LogicException
  */
 private function createModulesConfig($request, $dryRun = false)
 {
     $all = array_keys($this->moduleLoader->load());
     $deploymentConfig = $this->deploymentConfigReader->load();
     $currentModules = isset($deploymentConfig[ConfigOptionsListConstants::KEY_MODULES])
         ? $deploymentConfig[ConfigOptionsListConstants::KEY_MODULES] : [] ;
     $enable = $this->readListOfModules($all, $request, self::ENABLE_MODULES);
     $disable = $this->readListOfModules($all, $request, self::DISABLE_MODULES);
     $result = [];
     foreach ($all as $module) {
         if ((isset($currentModules[$module]) && !$currentModules[$module])) {
             $result[$module] = 0;
         } else {
             $result[$module] = 1;
         }
         if (in_array($module, $disable)) {
             $result[$module] = 0;
         }
         if (in_array($module, $enable)) {
             $result[$module] = 1;
         }
     }
     if (!$dryRun) {
         $this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_CONFIG => ['modules' => $result]], true);
     }
     return $result;
 }
Example #9
0
 /**
  * @param string $file
  * @param array $expected
  * @dataProvider loadDataProvider
  */
 public function testLoad($file, $expected)
 {
     $this->dirList->expects($this->once())->method('getPath')->with(DirectoryList::CONFIG)->willReturn(__DIR__ . '/_files');
     $object = new Reader($this->dirList, $file);
     $this->assertSame($expected, $object->load());
 }