Skip to content

Commit 44b2adf

Browse files
MAGETWO-71060: Remove zend json from package info #10340
2 parents a7f2db6 + a987761 commit 44b2adf

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lib/internal/Magento/Framework/Module/PackageInfo.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,32 @@ class PackageInfo
5959
protected $nonExistingDependencies = [];
6060

6161
/**
62-
* Constructor
63-
*
62+
* @var \Magento\Framework\Serialize\Serializer\Json
63+
*/
64+
private $serializer;
65+
66+
/**
6467
* @param Dir\Reader $reader
6568
* @param ComponentRegistrar $componentRegistrar
69+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
70+
* @throws \RuntimeException
6671
*/
67-
public function __construct(Dir\Reader $reader, ComponentRegistrar $componentRegistrar)
68-
{
72+
public function __construct(
73+
Dir\Reader $reader,
74+
ComponentRegistrar $componentRegistrar,
75+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
76+
) {
6977
$this->reader = $reader;
7078
$this->componentRegistrar = $componentRegistrar;
79+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
7181
}
7282

7383
/**
7484
* Load the packages information
7585
*
7686
* @return void
77-
* @throws \Zend_Json_Exception
87+
* @throws \InvalidArgumentException
7888
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7989
*/
8090
private function load()
@@ -85,9 +95,9 @@ private function load()
8595
$key = $moduleDir . '/composer.json';
8696
if (isset($jsonData[$key]) && $jsonData[$key]) {
8797
try {
88-
$packageData = \Zend_Json::decode($jsonData[$key]);
89-
} catch (\Zend_Json_Exception $e) {
90-
throw new \Zend_Json_Exception(
98+
$packageData = $this->serializer->unserialize($jsonData[$key]);
99+
} catch (\InvalidArgumentException $e) {
100+
throw new \InvalidArgumentException(
91101
sprintf(
92102
"%s composer.json error: %s",
93103
$moduleName,

lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ protected function setUp()
5454
->method('getComposerJsonFiles')
5555
->will($this->returnValue($fileIteratorMock));
5656

57-
$this->packageInfo = new PackageInfo($this->reader, $this->componentRegistrar);
57+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
58+
->getMock();
59+
60+
$this->serializerMock->expects($this->any())
61+
->method('unserialize')
62+
->willReturnCallback(
63+
function ($serializedData) {
64+
return json_decode($serializedData, true);
65+
}
66+
);
67+
$this->packageInfo = new PackageInfo(
68+
$this->reader,
69+
$this->componentRegistrar,
70+
$this->serializerMock
71+
);
5872
}
5973

6074
public function testGetModuleName()

0 commit comments

Comments
 (0)