Skip to content

Commit

Permalink
MAGETWO-80186: [2.2.x] - Remove zend json from migration #10341
Browse files Browse the repository at this point in the history
  • Loading branch information
irenelagno committed Sep 29, 2017
1 parent 4971b07 commit 0fa7c89
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
35 changes: 31 additions & 4 deletions lib/internal/Magento/Framework/Module/Setup/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0fa7c89

Please sign in to comment.