Skip to content

Commit ca04906

Browse files
MAGETWO-69535: Error during importing new list of scopes through shared file
1 parent 96ede40 commit ca04906

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

app/code/Magento/Store/App/Config/Source/InitialConfigSource.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\DeploymentConfig;
1010
use Magento\Framework\App\DeploymentConfig\Reader;
1111
use Magento\Framework\DataObject;
12+
use Magento\Framework\DataObjectFactory;
1213

1314
/**
1415
* Config source to retrieve configuration from files.
@@ -36,15 +37,28 @@ class InitialConfigSource implements ConfigSourceInterface
3637
*/
3738
private $configType;
3839

40+
/**
41+
* The DataObject factory.
42+
*
43+
* @var DataObjectFactory
44+
*/
45+
private $dataObjectFactory;
46+
3947
/**
4048
* @param Reader $reader The file reader
4149
* @param DeploymentConfig $deploymentConfig The deployment config reader
50+
* @param DataObjectFactory $dataObjectFactory The DataObject factory
4251
* @param string $configType The config type
4352
*/
44-
public function __construct(Reader $reader, DeploymentConfig $deploymentConfig, $configType)
45-
{
53+
public function __construct(
54+
Reader $reader,
55+
DeploymentConfig $deploymentConfig,
56+
DataObjectFactory $dataObjectFactory,
57+
$configType
58+
) {
4659
$this->reader = $reader;
4760
$this->deploymentConfig = $deploymentConfig;
61+
$this->dataObjectFactory = $dataObjectFactory;
4862
$this->configType = $configType;
4963
}
5064

@@ -59,11 +73,13 @@ public function get($path = '')
5973
*
6074
* @see \Magento\Store\Model\Config\Importer To import store configs
6175
*/
62-
if ($this->deploymentConfig->isAvailable()) {
76+
if (!$this->deploymentConfig->isAvailable()) {
6377
return [];
6478
}
6579

66-
$data = new DataObject($this->reader->load());
80+
$data = $this->dataObjectFactory->create([
81+
'data' => $this->reader->load()
82+
]);
6783

6884
if ($path !== '' && $path !== null) {
6985
$path = '/' . ltrim($path, '/');

app/code/Magento/Store/Test/Unit/App/Config/Source/InitialConfigSourceTest.php

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Framework\App\DeploymentConfig;
99
use Magento\Framework\App\DeploymentConfig\Reader;
10+
use Magento\Framework\DataObject;
11+
use Magento\Framework\DataObjectFactory;
1012
use Magento\Store\App\Config\Source\InitialConfigSource;
1113
use PHPUnit_Framework_MockObject_MockObject as Mock;
1214

@@ -25,6 +27,16 @@ class InitialConfigSourceTest extends \PHPUnit_Framework_TestCase
2527
*/
2628
private $deploymentConfigMock;
2729

30+
/**
31+
* @var DataObjectFactory|Mock
32+
*/
33+
private $dataObjectFactory;
34+
35+
/**
36+
* @var DataObject|Mock
37+
*/
38+
private $dataObjectMock;
39+
2840
/**
2941
* @var InitialConfigSource
3042
*/
@@ -41,26 +53,56 @@ public function setUp()
4153
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
4254
->disableOriginalConstructor()
4355
->getMock();
56+
$this->dataObjectFactory = $this->getMockBuilder(DataObjectFactory::class)
57+
->setMethods(['create'])
58+
->disableOriginalConstructor()
59+
->getMock();
60+
$this->dataObjectMock = $this->getMockBuilder(DataObject::class)
61+
->disableOriginalConstructor()
62+
->getMock();
4463

4564
$this->source = new InitialConfigSource(
4665
$this->readerMock,
4766
$this->deploymentConfigMock,
67+
$this->dataObjectFactory,
4868
'configType'
4969
);
5070
}
5171

52-
public function testGet()
72+
/**
73+
* @param string $path
74+
* @param array $data
75+
* @param string|array $expected
76+
* @dataProvider getDataProvider
77+
*/
78+
public function testGet($path, $data, $expected)
5379
{
54-
$path = 'path';
55-
5680
$this->readerMock->expects($this->once())
5781
->method('load')
58-
->willReturn(['configType' => [$path => 'value']]);
82+
->willReturn($data);
5983
$this->deploymentConfigMock->expects($this->once())
6084
->method('isAvailable')
6185
->willReturn(true);
86+
$this->dataObjectFactory->expects($this->once())
87+
->method('create')
88+
->with(['data' => $data])
89+
->willReturn($this->dataObjectMock);
90+
$this->dataObjectMock->expects($this->once())
91+
->method('getData')
92+
->willReturn($expected);
6293

63-
$this->assertEquals('value', $this->source->get($path));
94+
$this->assertEquals($expected, $this->source->get($path));
95+
}
96+
97+
/**
98+
* @return array
99+
*/
100+
public function getDataProvider()
101+
{
102+
return [
103+
'simple path' => ['path', ['configType' => 'value'], 'value'],
104+
'empty path' => ['', [], []]
105+
];
64106
}
65107

66108
public function testGetNotInstalled()

0 commit comments

Comments
 (0)