diff --git a/lib/internal/Magento/Framework/Module/Setup/Migration.php b/lib/internal/Magento/Framework/Module/Setup/Migration.php index 9d0c05a6b0986..1de26b5c9234a 100644 --- a/lib/internal/Magento/Framework/Module/Setup/Migration.php +++ b/lib/internal/Magento/Framework/Module/Setup/Migration.php @@ -128,19 +128,27 @@ class Migration */ private $setup; + /** + * @var \Magento\Framework\Serialize\Serializer\Json + */ + private $serializer; + /** * @param ModuleDataSetupInterface $setup * @param Filesystem $filesystem * @param MigrationData $migrationData * @param string $confPathToMapFile * @param array $compositeModules + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @throws \RuntimeException */ public function __construct( ModuleDataSetupInterface $setup, Filesystem $filesystem, MigrationData $migrationData, $confPathToMapFile, - $compositeModules = [] + $compositeModules = [], + \Magento\Framework\Serialize\Serializer\Json $serializer = null ) { $this->_directory = $filesystem->getDirectoryRead(DirectoryList::ROOT); $this->_pathToMapFile = $confPathToMapFile; @@ -151,6 +159,8 @@ public function __construct( ]; $this->_compositeModules = $compositeModules; $this->setup = $setup; + $this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** @@ -690,10 +700,27 @@ public function getCompositeModules() * * @param string $encodedValue * @param int $objectDecodeType - * @return mixed + * @return string|int|float|bool|array|null + * @throws \InvalidArgumentException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @deprecated + * @see \Magento\Framework\Module\Setup\Migration::jsonDecode + */ + protected function _jsonDecode($encodedValue, $objectDecodeType = 1) + { + return $this->jsonDecode($encodedValue); + } + + /** + * Decodes the given $encodedValue string which is + * encoded in the JSON format + * + * @param string $encodedValue + * @return string|int|float|bool|array|null + * @throws \InvalidArgumentException */ - protected function _jsonDecode($encodedValue, $objectDecodeType = \Zend_Json::TYPE_ARRAY) + private function jsonDecode($encodedValue) { - return \Zend_Json::decode($encodedValue, $objectDecodeType); + return $this->serializer->unserialize($encodedValue); } } diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php index a80b941e3b54b..51e86fcf68bee 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php @@ -144,7 +144,9 @@ public function testAppendClassAliasReplace() $setupMock, $filesystemMock, $migrationData, - 'app/etc/aliases_to_classes_map.json' + 'app/etc/aliases_to_classes_map.json', + [], + $this->getSerializerMock() ); $setupModel->appendClassAliasReplace( @@ -200,7 +202,8 @@ public function testDoUpdateClassAliases($replaceRules, $tableData, $expected, $ $filesystemMock, $migrationData, 'app/etc/aliases_to_classes_map.json', - $this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap) + $this->_getModelDependencies($tableRowsCount, $tableData, $aliasesMap), + $this->getSerializerMock() ); foreach ($replaceRules as $replaceRule) { @@ -245,4 +248,23 @@ protected function _getFilesystemMock() $mock = $this->getMockBuilder(\Magento\Framework\Filesystem::class)->disableOriginalConstructor()->getMock(); return $mock; } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Serialize\Serializer\Json + * @throws \PHPUnit_Framework_Exception + */ + private function getSerializerMock() + { + $serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) + ->getMock(); + + $serializerMock->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($serializedData) { + return json_decode($serializedData, true); + } + ); + return $serializerMock; + } }