Skip to content

Commit fcd7d5f

Browse files
committed
Remove the Zend_Json call from the Setup/Migration.php
- inject the new \Magento\Framework\Serialize\Serializer\Json class, - update _jsonDecode method parameter default from Zend_Json constant, - update _jsonDecode to call the new Serializer method version
1 parent a7f2db6 commit fcd7d5f

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ 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
@@ -144,7 +149,8 @@ public function __construct(
144149
Filesystem $filesystem,
145150
MigrationData $migrationData,
146151
$confPathToMapFile,
147-
$compositeModules = []
152+
$compositeModules = [],
153+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
148154
) {
149155
$this->_directory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
150156
$this->_pathToMapFile = $confPathToMapFile;
@@ -155,6 +161,8 @@ public function __construct(
155161
];
156162
$this->_compositeModules = $compositeModules;
157163
$this->setup = $setup;
164+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
165+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
158166
}
159167

160168
/**
@@ -694,10 +702,12 @@ public function getCompositeModules()
694702
*
695703
* @param string $encodedValue
696704
* @param int $objectDecodeType
697-
* @return mixed
705+
* @return array|bool|float|int|mixed|null|string
706+
* @throws \InvalidArgumentException
707+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
698708
*/
699-
protected function _jsonDecode($encodedValue, $objectDecodeType = \Zend_Json::TYPE_ARRAY)
709+
protected function _jsonDecode($encodedValue, $objectDecodeType = 1)
700710
{
701-
return \Zend_Json::decode($encodedValue, $objectDecodeType);
711+
return $this->serializer->unserialize($encodedValue);
702712
}
703713
}

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)