Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0fa7c89

Browse files
committed
MAGETWO-80186: [2.2.x] - Remove zend json from migration #10341
1 parent 4971b07 commit 0fa7c89

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

lib/internal/Magento/Framework/Module/Setup/Migration.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,27 @@ class Migration
128128
*/
129129
private $setup;
130130

131+
/**
132+
* @var \Magento\Framework\Serialize\Serializer\Json
133+
*/
134+
private $serializer;
135+
131136
/**
132137
* @param ModuleDataSetupInterface $setup
133138
* @param Filesystem $filesystem
134139
* @param MigrationData $migrationData
135140
* @param string $confPathToMapFile
136141
* @param array $compositeModules
142+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
143+
* @throws \RuntimeException
137144
*/
138145
public function __construct(
139146
ModuleDataSetupInterface $setup,
140147
Filesystem $filesystem,
141148
MigrationData $migrationData,
142149
$confPathToMapFile,
143-
$compositeModules = []
150+
$compositeModules = [],
151+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
144152
) {
145153
$this->_directory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
146154
$this->_pathToMapFile = $confPathToMapFile;
@@ -151,6 +159,8 @@ public function __construct(
151159
];
152160
$this->_compositeModules = $compositeModules;
153161
$this->setup = $setup;
162+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
163+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
154164
}
155165

156166
/**
@@ -690,10 +700,27 @@ public function getCompositeModules()
690700
*
691701
* @param string $encodedValue
692702
* @param int $objectDecodeType
693-
* @return mixed
703+
* @return string|int|float|bool|array|null
704+
* @throws \InvalidArgumentException
705+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
706+
* @deprecated
707+
* @see \Magento\Framework\Module\Setup\Migration::jsonDecode
708+
*/
709+
protected function _jsonDecode($encodedValue, $objectDecodeType = 1)
710+
{
711+
return $this->jsonDecode($encodedValue);
712+
}
713+
714+
/**
715+
* Decodes the given $encodedValue string which is
716+
* encoded in the JSON format
717+
*
718+
* @param string $encodedValue
719+
* @return string|int|float|bool|array|null
720+
* @throws \InvalidArgumentException
694721
*/
695-
protected function _jsonDecode($encodedValue, $objectDecodeType = \Zend_Json::TYPE_ARRAY)
722+
private function jsonDecode($encodedValue)
696723
{
697-
return \Zend_Json::decode($encodedValue, $objectDecodeType);
724+
return $this->serializer->unserialize($encodedValue);
698725
}
699726
}

lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ public function testAppendClassAliasReplace()
144144
$setupMock,
145145
$filesystemMock,
146146
$migrationData,
147-
'app/etc/aliases_to_classes_map.json'
147+
'app/etc/aliases_to_classes_map.json',
148+
[],
149+
$this->getSerializerMock()
148150
);
149151

150152
$setupModel->appendClassAliasReplace(
@@ -200,7 +202,8 @@ public function testDoUpdateClassAliases($replaceRules, $tableData, $expected, $
200202
$filesystemMock,
201203
$migrationData,
202204
'app/etc/aliases_to_classes_map.json',
203-
$this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap)
205+
$this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap),
206+
$this->getSerializerMock()
204207
);
205208

206209
foreach ($replaceRules as $replaceRule) {
@@ -245,4 +248,23 @@ protected function _getFilesystemMock()
245248
$mock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)->disableOriginalConstructor()->getMock();
246249
return $mock;
247250
}
251+
252+
/**
253+
* @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Serialize\Serializer\Json
254+
* @throws \PHPUnit_Framework_Exception
255+
*/
256+
private function getSerializerMock()
257+
{
258+
$serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
259+
->getMock();
260+
261+
$serializerMock->expects($this->any())
262+
->method('unserialize')
263+
->willReturnCallback(
264+
function ($serializedData) {
265+
return json_decode($serializedData, true);
266+
}
267+
);
268+
return $serializerMock;
269+
}
248270
}

0 commit comments

Comments
 (0)