Skip to content

Commit 3a91573

Browse files
author
Oleksii Korshenko
authored
MAGETWO-71061: Remove zend json from migration #10341
2 parents 2742ee8 + 630b2ac commit 3a91573

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
@@ -132,19 +132,27 @@ class Migration
132132
*/
133133
private $setup;
134134

135+
/**
136+
* @var \Magento\Framework\Serialize\Serializer\Json
137+
*/
138+
private $serializer;
139+
135140
/**
136141
* @param ModuleDataSetupInterface $setup
137142
* @param Filesystem $filesystem
138143
* @param MigrationData $migrationData
139144
* @param string $confPathToMapFile
140145
* @param array $compositeModules
146+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
147+
* @throws \RuntimeException
141148
*/
142149
public function __construct(
143150
ModuleDataSetupInterface $setup,
144151
Filesystem $filesystem,
145152
MigrationData $migrationData,
146153
$confPathToMapFile,
147-
$compositeModules = []
154+
$compositeModules = [],
155+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
148156
) {
149157
$this->_directory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
150158
$this->_pathToMapFile = $confPathToMapFile;
@@ -155,6 +163,8 @@ public function __construct(
155163
];
156164
$this->_compositeModules = $compositeModules;
157165
$this->setup = $setup;
166+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
167+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
158168
}
159169

160170
/**
@@ -694,10 +704,27 @@ public function getCompositeModules()
694704
*
695705
* @param string $encodedValue
696706
* @param int $objectDecodeType
697-
* @return mixed
707+
* @return string|int|float|bool|array|null
708+
* @throws \InvalidArgumentException
709+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
710+
* @deprecated
711+
* @see \Magento\Framework\Module\Setup\Migration::jsonDecode
712+
*/
713+
protected function _jsonDecode($encodedValue, $objectDecodeType = 1)
714+
{
715+
return $this->jsonDecode($encodedValue);
716+
}
717+
718+
/**
719+
* Decodes the given $encodedValue string which is
720+
* encoded in the JSON format
721+
*
722+
* @param string $encodedValue
723+
* @return string|int|float|bool|array|null
724+
* @throws \InvalidArgumentException
698725
*/
699-
protected function _jsonDecode($encodedValue, $objectDecodeType = \Zend_Json::TYPE_ARRAY)
726+
private function jsonDecode($encodedValue)
700727
{
701-
return \Zend_Json::decode($encodedValue, $objectDecodeType);
728+
return $this->serializer->unserialize($encodedValue);
702729
}
703730
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public function testAppendClassAliasReplace()
147147
$setupMock,
148148
$filesystemMock,
149149
$migrationData,
150-
'app/etc/aliases_to_classes_map.json'
150+
'app/etc/aliases_to_classes_map.json',
151+
[],
152+
$this->getSerializerMock()
151153
);
152154

153155
$setupModel->appendClassAliasReplace(
@@ -203,7 +205,8 @@ public function testDoUpdateClassAliases($replaceRules, $tableData, $expected, $
203205
$filesystemMock,
204206
$migrationData,
205207
'app/etc/aliases_to_classes_map.json',
206-
$this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap)
208+
$this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap),
209+
$this->getSerializerMock()
207210
);
208211

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

0 commit comments

Comments
 (0)