Skip to content

Commit 27db72c

Browse files
Merge pull request #1365 from magento-engcom/develop-prs
[EngCom] Public Pull Requests - MAGETWO-71060 Remove zend json from package info #10340 - MAGETWO-71059 Remove Zend_Json from setup #10339
2 parents a7f2db6 + 0b410fb commit 27db72c

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
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()

setup/src/Magento/Setup/Model/PackagesAuth.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,29 @@ class PackagesAuth
4949
*/
5050
private $filesystem;
5151

52+
/**
53+
* @var \Magento\Framework\Serialize\Serializer\Json
54+
*/
55+
private $serializer;
56+
5257
/**
5358
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
5459
* @param \Magento\Framework\HTTP\Client\Curl $curl
5560
* @param \Magento\Framework\Filesystem $filesystem
61+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
62+
* @throws \RuntimeException
5663
*/
5764
public function __construct(
5865
\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator,
5966
\Magento\Framework\HTTP\Client\Curl $curl,
60-
\Magento\Framework\Filesystem $filesystem
67+
\Magento\Framework\Filesystem $filesystem,
68+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
6169
) {
6270
$this->serviceLocator = $serviceLocator;
6371
$this->curlClient = $curl;
6472
$this->filesystem = $filesystem;
73+
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
74+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
6575
}
6676

6777
/**
@@ -85,9 +95,11 @@ public function getCredentialBaseUrl()
8595
* @param string $token
8696
* @param string $secretKey
8797
* @return string
98+
* @throws \InvalidArgumentException
8899
*/
89100
public function checkCredentials($token, $secretKey)
90101
{
102+
$response = ['success' => true];
91103
$serviceUrl = $this->getPackagesJsonUrl();
92104
$this->curlClient->setCredentials($token, $secretKey);
93105
try {
@@ -96,13 +108,13 @@ public function checkCredentials($token, $secretKey)
96108
$packagesInfo = $this->curlClient->getBody();
97109
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::COMPOSER_HOME);
98110
$directory->writeFile(self::PATH_TO_PACKAGES_FILE, $packagesInfo);
99-
return \Zend_Json::encode(['success' => true]);
100111
} else {
101-
return \Zend_Json::encode(['success' => false, 'message' => 'Bad credentials']);
112+
$response = ['success' => false, 'message' => 'Bad credentials'];
102113
}
103114
} catch (\Exception $e) {
104-
return \Zend_Json::encode(['success' => false, 'message' => $e->getMessage()]);
115+
$response = ['success' => false, 'message' => $e->getMessage()];
105116
}
117+
return $this->serializer->serialize($response);
106118
}
107119

108120
/**

setup/src/Magento/Setup/Test/Unit/Model/PackagesAuthTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class PackagesAuthTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
private $packagesAuth;
3030

31+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
32+
private $serializerMock;
33+
3134
public function setUp()
3235
{
3336
$zendServiceLocator = $this->getMock(\Zend\ServiceManager\ServiceLocatorInterface::class, [], [], '', false);
@@ -42,7 +45,21 @@ public function setUp()
4245
]);
4346
$this->curl = $this->getMock(\Magento\Framework\HTTP\Client\Curl::class, [], [], '', false);
4447
$this->filesystem = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
45-
$this->packagesAuth = new PackagesAuth($zendServiceLocator, $this->curl, $this->filesystem);
48+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
49+
->getMock();
50+
$this->serializerMock->expects($this->any())
51+
->method('serialize')
52+
->willReturnCallback(
53+
function ($serializedData) {
54+
return json_encode($serializedData);
55+
}
56+
);
57+
$this->packagesAuth = new PackagesAuth(
58+
$zendServiceLocator,
59+
$this->curl,
60+
$this->filesystem,
61+
$this->serializerMock
62+
);
4663
}
4764

4865
public function testCheckCredentialsActionBadCredentials()

0 commit comments

Comments
 (0)