Skip to content

Commit acc5353

Browse files
committed
Replace Zend_Json in the setup PackagesAuth with the new Serializer\Json
1 parent a7f2db6 commit acc5353

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

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

Lines changed: 15 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,6 +95,7 @@ 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
{
@@ -96,12 +107,12 @@ public function checkCredentials($token, $secretKey)
96107
$packagesInfo = $this->curlClient->getBody();
97108
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::COMPOSER_HOME);
98109
$directory->writeFile(self::PATH_TO_PACKAGES_FILE, $packagesInfo);
99-
return \Zend_Json::encode(['success' => true]);
110+
return $this->serializer->serialize(['success' => true]);
100111
} else {
101-
return \Zend_Json::encode(['success' => false, 'message' => 'Bad credentials']);
112+
return $this->serializer->serialize(['success' => false, 'message' => 'Bad credentials']);
102113
}
103114
} catch (\Exception $e) {
104-
return \Zend_Json::encode(['success' => false, 'message' => $e->getMessage()]);
115+
return $this->serializer->serialize(['success' => false, 'message' => $e->getMessage()]);
105116
}
106117
}
107118

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)