Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeploymentConfigTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\App\DeploymentConfig;
10 use \Magento\Framework\Config\ConfigOptionsListConstants;
11 
12 class DeploymentConfigTest extends \PHPUnit\Framework\TestCase
13 {
17  private static $fixture = [
18  'configData1' => 'scalar_value',
19  'configData2' => [
20  'foo' => 1,
21  'bar' => ['baz' => 2],
22  ],
23  ];
24 
28  private static $flattenedFixture = [
29  'configData1' => 'scalar_value',
30  'configData2' => [
31  'foo' => 1,
32  'bar' => ['baz' => 2],
33  ],
34  'configData2/foo' => 1,
35  'configData2/bar' => ['baz' => 2],
36  'configData2/bar/baz' => 2,
37  ];
38 
42  protected static $fixtureConfig;
43 
47  protected static $fixtureConfigMerged;
48 
52  protected $_deploymentConfig;
53 
58 
62  private $reader;
63 
64  public static function setUpBeforeClass()
65  {
66  self::$fixtureConfig = require __DIR__ . '/_files/config.php';
67  self::$fixtureConfigMerged = require __DIR__ . '/_files/other/local_developer_merged.php';
68  }
69 
70  protected function setUp()
71  {
72  $this->reader = $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class);
73  $this->_deploymentConfig = new \Magento\Framework\App\DeploymentConfig($this->reader, []);
74  $this->_deploymentConfigMerged = new \Magento\Framework\App\DeploymentConfig(
75  $this->reader,
76  require __DIR__ . '/_files/other/local_developer.php'
77  );
78  }
79 
80  public function testGetters()
81  {
82  $this->reader->expects($this->once())->method('load')->willReturn(self::$fixture);
83  $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get());
84  // second time to ensure loader will be invoked only once
85  $this->assertSame(self::$flattenedFixture, $this->_deploymentConfig->get());
86  $this->assertSame('scalar_value', $this->_deploymentConfig->getConfigData('configData1'));
87  $this->assertSame(self::$fixture['configData2'], $this->_deploymentConfig->getConfigData('configData2'));
88  }
89 
90  public function testIsAvailable()
91  {
92  $this->reader->expects($this->once())->method('load')->willReturn([
94  ]);
95  $object = new DeploymentConfig($this->reader);
96  $this->assertTrue($object->isAvailable());
97  }
98 
99  public function testNotAvailable()
100  {
101  $this->reader->expects($this->once())->method('load')->willReturn([]);
102  $object = new DeploymentConfig($this->reader);
103  $this->assertFalse($object->isAvailable());
104  }
105 
107  {
108  $this->reader->expects($this->at(0))->method('load')->willReturn([]);
109  $this->reader->expects($this->at(1))->method('load')->willReturn([
111  ]);
112  $object = new DeploymentConfig($this->reader);
113  $this->assertFalse($object->isAvailable());
114  $this->assertTrue($object->isAvailable());
115  }
116 
123  public function testKeyCollision(array $data)
124  {
125  $this->reader->expects($this->once())->method('load')->willReturn($data);
126  $object = new DeploymentConfig($this->reader);
127  $object->get();
128  }
129 
133  public function keyCollisionDataProvider()
134  {
135  return [
136  [
137  ['foo' => ['bar' => '1'], 'foo/bar' => '2'],
138  ['foo/bar' => '1', 'foo' => ['bar' => '2']],
139  ['foo' => ['subfoo' => ['subbar' => '1'], 'subfoo/subbar' => '2'], 'bar' => '3'],
140  ]
141  ];
142  }
143 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60