diff --git a/lib/internal/Magento/Framework/Module/PackageInfo.php b/lib/internal/Magento/Framework/Module/PackageInfo.php index 1fa4c6b824f15..7edb0c04ebf98 100644 --- a/lib/internal/Magento/Framework/Module/PackageInfo.php +++ b/lib/internal/Magento/Framework/Module/PackageInfo.php @@ -59,22 +59,32 @@ class PackageInfo protected $nonExistingDependencies = []; /** - * Constructor - * + * @var \Magento\Framework\Serialize\Serializer\Json + */ + private $serializer; + + /** * @param Dir\Reader $reader * @param ComponentRegistrar $componentRegistrar + * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer + * @throws \RuntimeException */ - public function __construct(Dir\Reader $reader, ComponentRegistrar $componentRegistrar) - { + public function __construct( + Dir\Reader $reader, + ComponentRegistrar $componentRegistrar, + \Magento\Framework\Serialize\Serializer\Json $serializer = null + ) { $this->reader = $reader; $this->componentRegistrar = $componentRegistrar; + $this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(\Magento\Framework\Serialize\Serializer\Json::class); } /** * Load the packages information * * @return void - * @throws \Zend_Json_Exception + * @throws \InvalidArgumentException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function load() @@ -85,9 +95,9 @@ private function load() $key = $moduleDir . '/composer.json'; if (isset($jsonData[$key]) && $jsonData[$key]) { try { - $packageData = \Zend_Json::decode($jsonData[$key]); - } catch (\Zend_Json_Exception $e) { - throw new \Zend_Json_Exception( + $packageData = $this->serializer->unserialize($jsonData[$key]); + } catch (\InvalidArgumentException $e) { + throw new \InvalidArgumentException( sprintf( "%s composer.json error: %s", $moduleName, diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php index e2e95f0d1d149..6c1f172b5c31c 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/PackageInfoTest.php @@ -54,7 +54,21 @@ protected function setUp() ->method('getComposerJsonFiles') ->will($this->returnValue($fileIteratorMock)); - $this->packageInfo = new PackageInfo($this->reader, $this->componentRegistrar); + $this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class) + ->getMock(); + + $this->serializerMock->expects($this->any()) + ->method('unserialize') + ->willReturnCallback( + function ($serializedData) { + return json_decode($serializedData, true); + } + ); + $this->packageInfo = new PackageInfo( + $this->reader, + $this->componentRegistrar, + $this->serializerMock + ); } public function testGetModuleName()