From baf9360bae4c2fb0ac94fbec173a6042f571076c Mon Sep 17 00:00:00 2001
From: Maddy Chellathurai <mchellathura@ebay.com>
Date: Mon, 4 May 2015 16:39:32 -0500
Subject: [PATCH] MAGETWO-34513: Move list to modules.php

- created env.php and moved related items to it.
---
 .gitignore                                    |  1 +
 .../Backend/Setup/ConfigOptionsList.php       |  2 +-
 .../Test/Unit/Setup/ConfigOptionsListTest.php |  2 +-
 .../Magento/Mtf/App/State/AbstractState.php   |  8 +-
 .../Magento/TestFramework/Application.php     |  6 +-
 .../TestFramework/ObjectManagerFactory.php    |  2 +-
 .../Magento/Framework/App/Bootstrap.php       | 14 +++-
 .../Magento/Framework/App/Cache/State.php     |  2 +-
 .../Framework/App/DeploymentConfig/Reader.php | 50 ++++++-----
 .../Framework/App/DeploymentConfig/Writer.php | 10 ++-
 .../Framework/App/ObjectManagerFactory.php    | 21 +++--
 .../Magento/Framework/App/Resource.php        |  7 +-
 .../App/Test/Unit/Cache/StateTest.php         |  2 +-
 .../Test/Unit/DeploymentConfig/ReaderTest.php | 84 ++++++++++++++-----
 .../Test/Unit/DeploymentConfig/WriterTest.php |  2 +-
 .../Unit/DeploymentConfig/_files/config.php   |  2 +-
 .../Unit/DeploymentConfig/_files/custom.php   |  2 +-
 .../_files/duplicateConfig.php                |  9 ++
 .../Test/Unit/DeploymentConfig/_files/env.php |  7 ++
 .../Framework/Config/ConfigGenerator.php      | 12 +--
 .../Framework/Config/ConfigOptionsList.php    |  1 +
 .../Framework/Config/File/ConfigFilePool.php  |  6 +-
 .../Config/Test/Unit/ConfigGeneratorTest.php  | 18 ++--
 .../Test/Unit/File/ConfigFilePoolTest.php     |  1 +
 .../Magento/Framework/Module/ModuleList.php   |  2 +-
 setup/src/Magento/Setup/Model/Installer.php   |  7 +-
 .../src/Magento/Setup/Model/ModuleStatus.php  |  2 +-
 27 files changed, 188 insertions(+), 94 deletions(-)
 create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php
 create mode 100644 lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php

diff --git a/.gitignore b/.gitignore
index 1e6c8cdcece..2c056b8004d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ atlassian*
 /.gitattributes
 /app/config_sandbox
 /app/etc/config.php
+/app/etc/env.php
 /app/code/Magento/TestModule*
 /lib/internal/flex/uploader/.actionScriptProperties
 /lib/internal/flex/uploader/.flexProperties
diff --git a/app/code/Magento/Backend/Setup/ConfigOptionsList.php b/app/code/Magento/Backend/Setup/ConfigOptionsList.php
index 83a953cd2f2..2acaa7759de 100644
--- a/app/code/Magento/Backend/Setup/ConfigOptionsList.php
+++ b/app/code/Magento/Backend/Setup/ConfigOptionsList.php
@@ -48,7 +48,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface
      */
     public function createConfig(array $options, DeploymentConfig $deploymentConfig)
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         if (isset($options[self::INPUT_KEY_BACKEND_FRONTNAME])) {
             $configData->set(self::CONFIG_PATH_BACKEND_FRONTNAME, $options[self::INPUT_KEY_BACKEND_FRONTNAME]);
diff --git a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php
index 279d11ddfbf..56f18a840a3 100644
--- a/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php
+++ b/app/code/Magento/Backend/Test/Unit/Setup/ConfigOptionsListTest.php
@@ -42,7 +42,7 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase
 
         $expectedData = [
             [
-                'file' => ConfigFilePool::APP_CONFIG,
+                'file' => ConfigFilePool::APP_ENV,
                 'segment' => 'backend',
                 'data' => [
                     'backend' => ['frontName' => 'admin']
diff --git a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php
index 39d384533ef..7548bc922bb 100644
--- a/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php
+++ b/dev/tests/functional/lib/Magento/Mtf/App/State/AbstractState.php
@@ -44,10 +44,12 @@ abstract class AbstractState implements StateInterface
         $dirList = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
             ->get('Magento\Framework\Filesystem\DirectoryList');
 
-        $reader = new Reader($dirList);
+        $configFilePool = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
+            ->get('\Magento\Framework\Config\File\ConfigFilePool');
+
+        $reader = new Reader($dirList, $configFilePool);
         $deploymentConfig = new DeploymentConfig($reader);
-        $dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
-        $dbInfo = $dbConfig['connection']['default'];
+        $dbInfo = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
         $host = $dbInfo['host'];
         $user = $dbInfo['username'];
         $password = $dbInfo['password'];
diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php
index 4d13da77e94..ca3ee5dbc85 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/Application.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php
@@ -162,10 +162,10 @@ class Application
     {
         if (null === $this->_db) {
             if ($this->isInstalled()) {
-                $reader = new Reader($this->dirList);
+                $configPool = new \Magento\Framework\Config\File\ConfigFilePool();
+                $reader = new Reader($this->dirList, $configPool);
                 $deploymentConfig = new DeploymentConfig($reader, []);
-                $dbConfig = $deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
-                $dbInfo = $dbConfig['connection']['default'];
+                $dbInfo = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
                 $host = $dbInfo['host'];
                 $user = $dbInfo['username'];
                 $password = $dbInfo['password'];
diff --git a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php
index e499e0d929a..763011a315b 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/ObjectManagerFactory.php
@@ -54,7 +54,7 @@ class ObjectManagerFactory extends \Magento\Framework\App\ObjectManagerFactory
         $objectManager->configure($this->_primaryConfigData);
         $objectManager->addSharedInstance($this->directoryList, 'Magento\Framework\App\Filesystem\DirectoryList');
         $objectManager->addSharedInstance($this->directoryList, 'Magento\Framework\Filesystem\DirectoryList');
-        $deploymentConfig = $this->createDeploymentConfig($directoryList, $arguments);
+        $deploymentConfig = $this->createDeploymentConfig($directoryList, $this->configFilePool, $arguments);
         $this->factory->setArguments($arguments);
         $objectManager->addSharedInstance($deploymentConfig, 'Magento\Framework\App\DeploymentConfig');
         $objectManager->addSharedInstance(
diff --git a/lib/internal/Magento/Framework/App/Bootstrap.php b/lib/internal/Magento/Framework/App/Bootstrap.php
index aaf238eadac..05fd99ceaa7 100644
--- a/lib/internal/Magento/Framework/App/Bootstrap.php
+++ b/lib/internal/Magento/Framework/App/Bootstrap.php
@@ -12,6 +12,7 @@ use Magento\Framework\Autoload\AutoloaderRegistry;
 use Magento\Framework\Autoload\Populator;
 use Magento\Framework\Filesystem\DriverPool;
 use Magento\Framework\Profiler;
+use Magento\Framework\Config\File\ConfigFilePool;
 
 /**
  * A bootstrap of Magento application
@@ -147,7 +148,8 @@ class Bootstrap
     {
         $dirList = self::createFilesystemDirectoryList($rootDir, $initParams);
         $driverPool = self::createFilesystemDriverPool($initParams);
-        return new ObjectManagerFactory($dirList, $driverPool);
+        $configFilePool = self::createConfigFilePool();
+        return new ObjectManagerFactory($dirList, $driverPool, $configFilePool);
     }
 
     /**
@@ -181,6 +183,16 @@ class Bootstrap
         return new DriverPool($extraDrivers);
     }
 
+    /**
+     * Creates instance of configuration files pool
+     *
+     * @return DriverPool
+     */
+    public static function createConfigFilePool()
+    {
+        return new ConfigFilePool();
+    }
+
     /**
      * Constructor
      *
diff --git a/lib/internal/Magento/Framework/App/Cache/State.php b/lib/internal/Magento/Framework/App/Cache/State.php
index d7de86d9ba3..20d55a3f001 100644
--- a/lib/internal/Magento/Framework/App/Cache/State.php
+++ b/lib/internal/Magento/Framework/App/Cache/State.php
@@ -98,7 +98,7 @@ class State implements StateInterface
     public function persist()
     {
         $this->load();
-        $this->writer->saveConfig([ConfigFilePool::APP_CONFIG => [self::CACHE_KEY => $this->statuses]]);
+        $this->writer->saveConfig([ConfigFilePool::APP_ENV => [self::CACHE_KEY => $this->statuses]]);
     }
 
     /**
diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php
index de210b42871..ecc591efecc 100644
--- a/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php
+++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php
@@ -7,6 +7,7 @@
 namespace Magento\Framework\App\DeploymentConfig;
 
 use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Config\File\ConfigFilePool;
 
 /**
  * Deployment configuration reader
@@ -14,69 +15,80 @@ use Magento\Framework\App\Filesystem\DirectoryList;
 class Reader
 {
     /**
-     * Default configuration file name
+     * @var DirectoryList
      */
-    const DEFAULT_FILE = 'config.php';
+    private $dirList;
 
     /**
-     * Directory list object
-     *
-     * @var DirectoryList
+     * @var ConfigFilePool
      */
-    private $dirList;
+    private $configFilePool;
 
     /**
-     * Custom file name
+     * Configuration file names
      *
-     * @var string
+     * @var array
      */
-    private $file;
+    private $files;
 
     /**
      * Constructor
      *
      * @param DirectoryList $dirList
+     * @param ConfigFilePool $configFilePool
      * @param null|string $file
      * @throws \InvalidArgumentException
      */
-    public function __construct(DirectoryList $dirList, $file = null)
+    public function __construct(DirectoryList $dirList, ConfigFilePool $configFilePool, $file = null)
     {
         $this->dirList = $dirList;
+        $this->configFilePool = $configFilePool;
         if (null !== $file) {
             if (!preg_match('/^[a-z\d\.\-]+\.php$/i', $file)) {
                 throw new \InvalidArgumentException("Invalid file name: {$file}");
             }
-            $this->file = $file;
+            $this->files = [$file];
         } else {
-            $this->file = self::DEFAULT_FILE;
+            $this->files = $this->configFilePool->getPaths();
         }
     }
 
     /**
      * Gets the file name
      *
-     * @return string
+     * @return array
      */
-    public function getFile()
+    public function getFiles()
     {
-        return $this->file;
+        return $this->files;
     }
 
     /**
      * Loads the configuration file
      *
      * @param string $configFile
+     * @throws \Exception
      * @return array
      */
     public function load($configFile = null)
     {
+        $path = $this->dirList->getPath(DirectoryList::CONFIG);
         if ($configFile) {
-            $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $configFile;
+            $result = @include $path . '/' . $this->configFilePool->getPath($configFile);
         } else {
-            $file = $this->dirList->getPath(DirectoryList::CONFIG) . '/' . $this->file;
-        }
+            $configFiles = $this->configFilePool->getPaths();
+            $result = [];
+            foreach ($configFiles as $fileKey => $config) {
+                $configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
+                $fileData = @include $configFile;
 
-        $result = @include $file;
+                if (empty(array_intersect_key($result, $fileData))) {
+                    $result = array_replace_recursive($result, $fileData ?: []);
+                } else {
+                    throw new \Exception('Duplicate keys are present');
+                }
+            }
+        }
         return $result ?: [];
     }
 }
diff --git a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php
index 644af48555d..8d447e295bf 100644
--- a/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php
+++ b/lib/internal/Magento/Framework/App/DeploymentConfig/Writer.php
@@ -78,10 +78,12 @@ class Writer
     public function checkIfWritable()
     {
         $configDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG);
-        if ($configDirectory->isWritable($this->reader->getFile())) {
-            return true;
+        foreach ($this->reader->getFiles() as $file) {
+            if (!$configDirectory->isWritable($file)) {
+                return false;
+            }
         }
-        return false;
+        return true;
     }
 
     /**
@@ -99,7 +101,7 @@ class Writer
             if (isset($paths[$fileKey])) {
 
                 if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
-                    $currentData = $this->reader->load($paths[$fileKey]);
+                    $currentData = $this->reader->load($fileKey);
                     if ($override) {
                         $config = array_merge($currentData, $config);
                     } else {
diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
index c712e82a264..fff951bef25 100644
--- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
+++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php
@@ -12,8 +12,7 @@ use Magento\Framework\Filesystem\DriverPool;
 use Magento\Framework\Interception\ObjectManager\ConfigInterface;
 use Magento\Framework\ObjectManager\Definition\Compiled\Serialized;
 use Magento\Framework\App\ObjectManager\Environment;
-use Magento\Framework\App\EnvironmentFactory;
-use Magento\Framework\App\EnvironmentInterface;
+use Magento\Framework\Config\File\ConfigFilePool;
 
 /**
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -71,6 +70,13 @@ class ObjectManagerFactory
      */
     protected $driverPool;
 
+    /**
+     * Configuration file pool
+     *
+     * @var ConfigFilePool
+     */
+    protected $configFilePool;
+
     /**
      * Factory
      *
@@ -83,11 +89,13 @@ class ObjectManagerFactory
      *
      * @param DirectoryList $directoryList
      * @param DriverPool $driverPool
+     * @param ConfigFilePool $configFilePool
      */
-    public function __construct(DirectoryList $directoryList, DriverPool $driverPool)
+    public function __construct(DirectoryList $directoryList, DriverPool $driverPool, ConfigFilePool $configFilePool)
     {
         $this->directoryList = $directoryList;
         $this->driverPool = $driverPool;
+        $this->configFilePool = $configFilePool;
     }
 
     /**
@@ -100,7 +108,7 @@ class ObjectManagerFactory
      */
     public function create(array $arguments)
     {
-        $deploymentConfig = $this->createDeploymentConfig($this->directoryList, $arguments);
+        $deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
         $arguments = array_merge($deploymentConfig->get(), $arguments);
         $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory(
             $this->driverPool->getDriver(DriverPool::FILE),
@@ -179,10 +187,11 @@ class ObjectManagerFactory
      * Creates deployment configuration object
      *
      * @param DirectoryList $directoryList
+     * @param ConfigFilePool $configFilePool
      * @param array $arguments
      * @return DeploymentConfig
      */
-    protected function createDeploymentConfig(DirectoryList $directoryList, array $arguments)
+    protected function createDeploymentConfig(DirectoryList $directoryList, ConfigFilePool $configFilePool, array $arguments)
     {
         $customFile = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE])
             ? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG_FILE]
@@ -190,7 +199,7 @@ class ObjectManagerFactory
         $customData = isset($arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG])
             ? $arguments[self::INIT_PARAM_DEPLOYMENT_CONFIG]
             : [];
-        $reader = new DeploymentConfig\Reader($directoryList, $customFile);
+        $reader = new DeploymentConfig\Reader($directoryList, $configFilePool, $customFile);
         return new DeploymentConfig($reader, $customData);
     }
 
diff --git a/lib/internal/Magento/Framework/App/Resource.php b/lib/internal/Magento/Framework/App/Resource.php
index b38629a460a..02edd51d599 100644
--- a/lib/internal/Magento/Framework/App/Resource.php
+++ b/lib/internal/Magento/Framework/App/Resource.php
@@ -104,11 +104,8 @@ class Resource
             return $this->_connections[$connectionName];
         }
 
-        $dbInfo = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
-        if (null === $dbInfo) {
-            return false;
-        }
-        $connectionConfig = $dbInfo['connection'][$connectionName];
+        $connections = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTIONS);
+        $connectionConfig = $connections[$connectionName];
         if ($connectionConfig) {
             $connection = $this->_connectionFactory->create($connectionConfig);
         }
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php
index c5767244b54..8278d0fdfe4 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/Cache/StateTest.php
@@ -93,7 +93,7 @@ class StateTest extends \PHPUnit_Framework_TestCase
     {
         $model = new State($this->config, $this->writer);
         $this->config->expects($this->once())->method('getConfigData')->willReturn(['test_cache_type' => true]);
-        $configValue = [ConfigFilePool::APP_CONFIG => ['cache_types' => ['test_cache_type' => true]]];
+        $configValue = [ConfigFilePool::APP_ENV => ['cache_types' => ['test_cache_type' => true]]];
         $this->writer->expects($this->once())->method('saveConfig')->with($configValue);
         $model->persist();
     }
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php
index a1bce3da6da..561a4961920 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/ReaderTest.php
@@ -6,9 +6,9 @@
 
 namespace Magento\Framework\App\Test\Unit\DeploymentConfig;
 
-use \Magento\Framework\App\DeploymentConfig\Reader;
-
+use Magento\Framework\App\DeploymentConfig\Reader;
 use Magento\Framework\App\Filesystem\DirectoryList;
+use Magento\Framework\Config\File\ConfigFilePool;
 
 class ReaderTest extends \PHPUnit_Framework_TestCase
 {
@@ -17,17 +17,33 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
      */
     private $dirList;
 
+    /**
+     * @var \PHPUnit_Framework_MockObject_MockObject
+     */
+    private $configFilePool;
+
     protected function setUp()
     {
         $this->dirList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
+        $this->dirList->expects($this->any())
+            ->method('getPath')
+            ->with(DirectoryList::CONFIG)
+            ->willReturn(__DIR__ . '/_files');
+        $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false);
+        $this->configFilePool
+            ->expects($this->any())
+            ->method('getPaths')
+            ->willReturn(['configKeyOne' => 'config.php', 'configKeyTwo' => 'env.php']);
     }
 
     public function testGetFile()
     {
-        $object = new Reader($this->dirList);
-        $this->assertEquals(Reader::DEFAULT_FILE, $object->getFile());
-        $object = new Reader($this->dirList, 'custom.php');
-        $this->assertEquals('custom.php', $object->getFile());
+        $object = new Reader($this->dirList, $this->configFilePool);
+        $files = $object->getFiles();
+        $this->assertArrayHasKey('configKeyOne', $files);
+        $this->assertArrayHasKey('configKeyTwo', $files);
+        $object = new Reader($this->dirList, $this->configFilePool, 'customOne.php');
+        $this->assertEquals(['customOne.php'], $object->getFiles());
     }
 
     /**
@@ -36,34 +52,62 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
      */
     public function testWrongFile()
     {
-        new Reader($this->dirList, 'invalid_name');
+        new Reader($this->dirList, $this->configFilePool, 'invalid_name');
+    }
+
+    public function testLoad()
+    {
+        $files = [['configKeyOne', 'config.php'], ['configKeyTwo','env.php']];
+        $this->configFilePool
+            ->expects($this->any())
+            ->method('getPath')
+            ->will($this->returnValueMap($files));
+        $object = new Reader($this->dirList, $this->configFilePool);
+        $this->assertSame(['fooKey' =>'foo', 'barKey' => 'bar', 'envKey' => 'env'], $object->load());
     }
 
     /**
      * @param string $file
      * @param array $expected
-     * @dataProvider loadDataProvider
+     * @dataProvider loadCustomDataProvider
      */
-    public function testLoad($file, $expected)
+    public function testCustomLoad($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());
+        $configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false);
+        $configFilePool->expects($this->any())->method('getPaths')->willReturn(['custom.php']);
+        $configFilePool->expects($this->any())->method('getPath')->willReturn('custom.php');
+        $object = new Reader($this->dirList, $configFilePool, 'custom.php');
+        $this->assertSame(['bazKey' => 'baz'], $object->load());
     }
 
     /**
      * @return array
      */
-    public function loadDataProvider()
+    public function loadCustomDataProvider()
     {
         return [
-            [null, ['foo', 'bar']],
-            ['config.php', ['foo', 'bar']],
-            ['custom.php', ['baz']],
-            ['nonexistent.php', []]
+            ['custom.php', ['bazKey' => 'baz']],
+            ['nonexistent.php', []],
         ];
     }
+
+    /**
+     * @expectedException \Exception
+     * @expectedExceptionMessage Duplicate keys are present
+     */
+    public function testDuplicateLoad()
+    {
+        $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, $configFilePool);
+        $this->assertSame(['fooKey' =>'foo', 'barKey' => 'bar'], $object->load());
+    }
 }
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php
index e1ab784199f..d9494ec1c3c 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/WriterTest.php
@@ -59,7 +59,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
             $this->deploymentConfig,
             $this->formatter
         );
-        $this->reader->expects($this->any())->method('getFile')->willReturn('test.php');
+        $this->reader->expects($this->any())->method('getFiles')->willReturn('test.php');
         $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
         $filesystem->expects($this->any())
             ->method('getDirectoryWrite')
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php
index e5519913e59..569b3df8398 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/config.php
@@ -4,4 +4,4 @@
  * See COPYING.txt for license details.
  */
 
-return ['foo', 'bar'];
+return ['fooKey' => 'foo', 'barKey' => 'bar'];
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php
index 22cd13edb67..4e57bcc5158 100644
--- a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/custom.php
@@ -4,4 +4,4 @@
  * See COPYING.txt for license details.
  */
 
-return ['baz'];
+return ['bazKey' => 'baz'];
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php
new file mode 100644
index 00000000000..c344e00adae
--- /dev/null
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/duplicateConfig.php
@@ -0,0 +1,9 @@
+<?php
+/**
+ * {license_notice}
+ *
+ * @copyright   {copyright}
+ * @license     {license_link}
+ */
+
+return ['barKey' => 'someOtherBar'];
diff --git a/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php
new file mode 100644
index 00000000000..660088939bc
--- /dev/null
+++ b/lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/_files/env.php
@@ -0,0 +1,7 @@
+<?php
+/**
+ * Copyright © 2015 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+return ['envKey' => 'env'];
diff --git a/lib/internal/Magento/Framework/Config/ConfigGenerator.php b/lib/internal/Magento/Framework/Config/ConfigGenerator.php
index c7f4ac934ae..dd15c2cae8c 100644
--- a/lib/internal/Magento/Framework/Config/ConfigGenerator.php
+++ b/lib/internal/Magento/Framework/Config/ConfigGenerator.php
@@ -63,7 +63,7 @@ class ConfigGenerator
      */
     public function createInstallConfig()
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE) === null) {
             $configData->set(ConfigOptionsList::CONFIG_PATH_INSTALL_DATE, date('r'));
@@ -80,7 +80,7 @@ class ConfigGenerator
     {
         $currentKey = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_CRYPT_KEY);
 
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
         if (isset($data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY])) {
             if ($currentKey !== null) {
                 $key = $currentKey . "\n" . $data[ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY];
@@ -106,7 +106,7 @@ class ConfigGenerator
      */
     public function createSessionConfig(array $data)
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         if (isset($data[ConfigOptionsList::INPUT_KEY_SESSION_SAVE])) {
             $configData->set(
@@ -126,7 +126,7 @@ class ConfigGenerator
      */
     public function createDefinitionsConfig(array $data)
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         if (!empty($data[ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT])) {
             $configData->set(
@@ -146,7 +146,7 @@ class ConfigGenerator
      */
     public function createDbConfig(array $data)
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         $optional = [
             ConfigOptionsList::INPUT_KEY_DB_HOST,
@@ -188,7 +188,7 @@ class ConfigGenerator
      */
     public function createResourceConfig()
     {
-        $configData = new ConfigData(ConfigFilePool::APP_CONFIG);
+        $configData = new ConfigData(ConfigFilePool::APP_ENV);
 
         if ($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP) === null) {
             $configData->set(ConfigOptionsList::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default');
diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php
index ac1a90652f4..0e994e29ac2 100644
--- a/lib/internal/Magento/Framework/Config/ConfigOptionsList.php
+++ b/lib/internal/Magento/Framework/Config/ConfigOptionsList.php
@@ -25,6 +25,7 @@ class ConfigOptionsList implements ConfigOptionsListInterface
     const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format';
     const CONFIG_PATH_RESOURCE_DEFAULT_SETUP = 'resource/default_setup/connection';
     const CONFIG_PATH_DB_CONNECTION_DEFAULT = 'db/connection/default/';
+    const CONFIG_PATH_DB_CONNECTIONS= 'db/connection/';
     const CONFIG_PATH_DB_PREFIX = 'db/table_prefix';
     /**#@-*/
 
diff --git a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php
index 882e846ec14..b1d8e2d4623 100644
--- a/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php
+++ b/lib/internal/Magento/Framework/Config/File/ConfigFilePool.php
@@ -6,14 +6,13 @@
 
 namespace Magento\Framework\Config\File;
 
-use Magento\Framework\App\Filesystem\DirectoryList;
-
 /**
  * Stores file key to file name config
  */
 class ConfigFilePool
 {
     const APP_CONFIG = 'app_config';
+    const APP_ENV = 'app_env';
 
     /**
      * Default application config
@@ -21,7 +20,8 @@ class ConfigFilePool
      * @var array
      */
     private $applicationConfigFiles = [
-        self::APP_CONFIG => 'config.php'
+        self::APP_CONFIG => 'config.php',
+        self::APP_ENV => 'env.php',
     ];
 
     /**
diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php
index 8479894c4e7..fd6498d5924 100644
--- a/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php
+++ b/lib/internal/Magento/Framework/Config/Test/Unit/ConfigGeneratorTest.php
@@ -29,21 +29,21 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase
     {
         $returnValue = $this->configGeneratorObject->createInstallConfig([]);
         $this->assertInstanceOf('Magento\Framework\Config\Data\ConfigData', $returnValue);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
     }
 
     public function testCreateCryptConfigWithInput()
     {
         $testData = [ConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY => 'some-test_key'];
         $returnValue = $this->configGeneratorObject->createCryptConfig($testData);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['crypt' => ['key' => 'some-test_key']], $returnValue->getData());
     }
 
     public function testCreateCryptConfigWithoutInput()
     {
         $returnValue = $this->configGeneratorObject->createCryptConfig([]);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['crypt' => ['key' => md5('key')]], $returnValue->getData());
     }
 
@@ -51,19 +51,19 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase
     {
         $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'files'];
         $returnValue = $this->configGeneratorObject->createSessionConfig($testData);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_FILES]], $returnValue->getData());
 
         $testData = [ConfigOptionsList::INPUT_KEY_SESSION_SAVE => 'db'];
         $returnValue = $this->configGeneratorObject->createSessionConfig($testData);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['session' => ['save' => ConfigOptionsList::SESSION_SAVE_DB]], $returnValue->getData());
     }
 
     public function testCreateSessionConfigWithoutInput()
     {
         $returnValue = $this->configGeneratorObject->createSessionConfig([]);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals([], $returnValue->getData());
     }
 
@@ -71,7 +71,7 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase
     {
         $testData = [\Magento\Framework\Config\ConfigOptionsList::INPUT_KEY_DEFINITION_FORMAT => 'test-format'];
         $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['definition' => ['format' => 'test-format']], $returnValue->getData());
     }
 
@@ -84,7 +84,7 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase
             ConfigOptionsList::INPUT_KEY_DB_PREFIX => 'testSomePrefix',
         ];
         $returnValue = $this->configGeneratorObject->createDbConfig($testData);
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $dbData = $returnValue->getData();
         $dbData = $dbData['db'];
         $this->assertArrayHasKey('table_prefix', $dbData);
@@ -104,7 +104,7 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase
     public function testCreateResourceConfig()
     {
         $returnValue = $this->configGeneratorObject->createResourceConfig();
-        $this->assertEquals(ConfigFilePool::APP_CONFIG, $returnValue->getFileKey());
+        $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey());
         $this->assertEquals(['resource' => ['default_setup' => ['connection' => 'default']]], $returnValue->getData());
     }
 }
diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php
index 52bc10dc59b..24452acb433 100644
--- a/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php
+++ b/lib/internal/Magento/Framework/Config/Test/Unit/File/ConfigFilePoolTest.php
@@ -27,6 +27,7 @@ class ConfigFilePoolTest extends \PHPUnit_Framework_TestCase
     {
         $expected['new_key'] = 'new_config.php';
         $expected[ConfigFilePool::APP_CONFIG] = 'config.php';
+        $expected[ConfigFilePool::APP_ENV] = 'env.php';
 
         $this->assertEquals($expected, $this->configFilePool->getPaths());
     }
diff --git a/lib/internal/Magento/Framework/Module/ModuleList.php b/lib/internal/Magento/Framework/Module/ModuleList.php
index aa5cf2dc920..604d43fa04c 100644
--- a/lib/internal/Magento/Framework/Module/ModuleList.php
+++ b/lib/internal/Magento/Framework/Module/ModuleList.php
@@ -140,7 +140,7 @@ class ModuleList implements ModuleListInterface
     private function loadConfigData()
     {
         if (null === $this->configData && ($this->config->isAvailable())) {
-            $this->configData = $this->config->getConfigData(ConfigOptionsList::KEY_MODULES);
+            $this->configData = $this->config->get(ConfigOptionsList::KEY_MODULES);
         }
     }
 }
diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php
index 5db3a546a66..a3a8f298bbd 100644
--- a/setup/src/Magento/Setup/Model/Installer.php
+++ b/setup/src/Magento/Setup/Model/Installer.php
@@ -1028,9 +1028,7 @@ class Installer
     {
         // stops cleanup if app/etc/config.php does not exist
         if ($this->deploymentConfig->isAvailable()) {
-            $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
-            $config = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION];
-
+            $config = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
             if ($config) {
                 try {
                     $connection = $this->connectionFactory->create($config);
@@ -1093,8 +1091,7 @@ class Installer
      */
     private function assertDbAccessible()
     {
-        $dbConfig = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_DB);
-        $connectionConfig = $dbConfig['connection'][Config::DEFAULT_SETUP_CONNECTION];
+        $connectionConfig = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DB_CONNECTION_DEFAULT);
         $this->checkDatabaseConnection(
             $connectionConfig[ConfigOptionsList::KEY_NAME],
             $connectionConfig[ConfigOptionsList::KEY_HOST],
diff --git a/setup/src/Magento/Setup/Model/ModuleStatus.php b/setup/src/Magento/Setup/Model/ModuleStatus.php
index d49206b274a..bfc8d9349a3 100644
--- a/setup/src/Magento/Setup/Model/ModuleStatus.php
+++ b/setup/src/Magento/Setup/Model/ModuleStatus.php
@@ -145,7 +145,7 @@ class ModuleStatus
      */
     private function deselectDisabledModules()
     {
-        $existingModules = $this->deploymentConfig->getConfigData(ConfigOptionsList::KEY_MODULES);
+        $existingModules = $this->deploymentConfig->get(ConfigOptionsList::KEY_MODULES);
         if (isset($existingModules)) {
             foreach ($existingModules as $module => $value) {
                 if (!$value) {
-- 
GitLab