Skip to content

Commit c278011

Browse files
MAGETWO-66656: Fix retrieval of old value in config import
1 parent 0647d8d commit c278011

File tree

2 files changed

+11
-46
lines changed

2 files changed

+11
-46
lines changed

app/code/Magento/Config/Model/PreparedValueFactory.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
use Magento\Config\Model\Config\StructureFactory;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\App\Config\ValueInterface;
13-
use Magento\Framework\App\DeploymentConfig;
1413
use Magento\Framework\App\Config\Value;
15-
use Magento\Framework\App\Config\ValueInterface;
16-
use Magento\Framework\App\Config\Value;
17-
use Magento\Framework\App\Config\ValueFactory;
1814
use Magento\Framework\App\ScopeInterface;
1915
use Magento\Framework\App\ScopeResolverPool;
2016
use Magento\Framework\Exception\RuntimeException;
@@ -92,25 +88,15 @@ public function create($path, $value, $scope, $scopeCode = null)
9288
$structure = $this->structureFactory->create();
9389
/** @var Structure\ElementInterface $field */
9490
$field = $structure->getElement($path);
91+
/** @var string $backendModelName */
92+
$backendModelName = $field instanceof Structure\Element\Field && $field->hasBackendModel()
93+
? $field->getData()['backend_model']
94+
: ValueInterface::class;
9595
/** @var ValueInterface $backendModel */
96-
$backendModel = $field instanceof Structure\Element\Field && $field->hasBackendModel()
97-
? $field->getBackendModel()
98-
: $this->valueFactory->create();
99-
/** @var Structure $structure */
100-
$structure = $this->structureFactory->create();
101-
/** @var Structure\ElementInterface $field */
102-
$field = $this->deploymentConfig->isAvailable()
103-
? $structure->getElement($path)
104-
: null;
105-
/** @var string $backendModelName */
106-
$backendModelName = $field instanceof Structure\Element\Field && $field->hasBackendModel()
107-
? $field->getData()['backend_model']
108-
: ValueInterface::class;
109-
/** @var ValueInterface $backendModel */
110-
$backendModel = $this->valueFactory->create(
111-
$backendModelName,
112-
['config' => $this->config]
113-
);
96+
$backendModel = $this->valueFactory->create(
97+
$backendModelName,
98+
['config' => $this->config]
99+
);
114100

115101
if ($backendModel instanceof Value) {
116102
$scopeId = 0;

app/code/Magento/Config/Test/Unit/Model/PreparedValueFactoryTest.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
use Magento\Config\Model\Config\BackendFactory;
99
use Magento\Config\Model\PreparedValueFactory;
1010
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\App\DeploymentConfig;
12-
use Magento\Config\Model\Config\StructureFactory;
13-
use Magento\Framework\App\Config\Value;
14-
use Magento\Config\Model\Config\Structure;
15-
use Magento\Config\Model\Config\Structure\Element\Field;
16-
use Magento\Framework\App\Config\ValueFactory;
1711
use Magento\Config\Model\Config\StructureFactory;
1812
use Magento\Framework\App\Config\Value;
1913
use Magento\Config\Model\Config\Structure;
@@ -34,8 +28,7 @@ class PreparedValueFactoryTest extends \PHPUnit_Framework_TestCase
3428
private $structureFactoryMock;
3529

3630
/**
37-
* @var BackendFactory|\PHPUnit_Framework_MockObject_MockObject
38-
* @var ValueFactory|Mock
31+
* @var BackendFactory|Mock
3932
*/
4033
private $valueFactoryMock;
4134

@@ -55,7 +48,7 @@ class PreparedValueFactoryTest extends \PHPUnit_Framework_TestCase
5548
private $fieldMock;
5649

5750
/**
58-
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
51+
* @var ScopeConfigInterface|Mock
5952
*/
6053
private $configMock;
6154

@@ -159,10 +152,7 @@ public function testCreate(
159152
$this->fieldMock->expects($this->once())
160153
->method('hasBackendModel')
161154
->willReturn(true);
162-
$this->fieldMock->expects($this->once())
163-
->method('getBackendModel')
164-
->willReturn($this->valueMock);
165-
$this->valueFactoryMock->expects($this->never())
155+
$this->valueFactoryMock->expects($this->once())
166156
->method('create')
167157
->willReturn($this->valueMock);
168158
$this->valueMock->expects($this->once())
@@ -271,17 +261,6 @@ public function createNotInstanceOfValueDataProvider()
271261
'someScope',
272262
'someScopeCode',
273263
1,
274-
[
275-
'deploymentConfigIsAvailable' => ['return' => true],
276-
'structureGetElement' => ['expects' => $this->once()],
277-
'field' => [
278-
'hasBackendModel' => [
279-
'expects' => $this->once(),
280-
'return' => true
281-
],
282-
'getBackendModel' => ['expects' => $this->never()]
283-
],
284-
'valueFactory' => ['expects' => $this->once()]
285264
],
286265
'default scope flow' => [
287266
'/some/path',

0 commit comments

Comments
 (0)