Skip to content

Commit

Permalink
MAGETWO-71059: Remove Zend_Json from setup #10339
Browse files Browse the repository at this point in the history
  • Loading branch information
ishakhsuvarov authored Jul 27, 2017
2 parents 44b2adf + 21abedf commit 0b410fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
20 changes: 16 additions & 4 deletions setup/src/Magento/Setup/Model/PackagesAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,29 @@ class PackagesAuth
*/
private $filesystem;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
* @param \Magento\Framework\HTTP\Client\Curl $curl
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator,
\Magento\Framework\HTTP\Client\Curl $curl,
\Magento\Framework\Filesystem $filesystem
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->serviceLocator = $serviceLocator;
$this->curlClient = $curl;
$this->filesystem = $filesystem;
$this->serializer = $serializer?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
Expand All @@ -85,9 +95,11 @@ public function getCredentialBaseUrl()
* @param string $token
* @param string $secretKey
* @return string
* @throws \InvalidArgumentException
*/
public function checkCredentials($token, $secretKey)
{
$response = ['success' => true];
$serviceUrl = $this->getPackagesJsonUrl();
$this->curlClient->setCredentials($token, $secretKey);
try {
Expand All @@ -96,13 +108,13 @@ public function checkCredentials($token, $secretKey)
$packagesInfo = $this->curlClient->getBody();
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::COMPOSER_HOME);
$directory->writeFile(self::PATH_TO_PACKAGES_FILE, $packagesInfo);
return \Zend_Json::encode(['success' => true]);
} else {
return \Zend_Json::encode(['success' => false, 'message' => 'Bad credentials']);
$response = ['success' => false, 'message' => 'Bad credentials'];
}
} catch (\Exception $e) {
return \Zend_Json::encode(['success' => false, 'message' => $e->getMessage()]);
$response = ['success' => false, 'message' => $e->getMessage()];
}
return $this->serializer->serialize($response);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion setup/src/Magento/Setup/Test/Unit/Model/PackagesAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class PackagesAuthTest extends \PHPUnit_Framework_TestCase
*/
private $packagesAuth;

/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
private $serializerMock;

public function setUp()
{
$zendServiceLocator = $this->getMock(\Zend\ServiceManager\ServiceLocatorInterface::class, [], [], '', false);
Expand All @@ -42,7 +45,21 @@ public function setUp()
]);
$this->curl = $this->getMock(\Magento\Framework\HTTP\Client\Curl::class, [], [], '', false);
$this->filesystem = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
$this->packagesAuth = new PackagesAuth($zendServiceLocator, $this->curl, $this->filesystem);
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
->getMock();
$this->serializerMock->expects($this->any())
->method('serialize')
->willReturnCallback(
function ($serializedData) {
return json_encode($serializedData);
}
);
$this->packagesAuth = new PackagesAuth(
$zendServiceLocator,
$this->curl,
$this->filesystem,
$this->serializerMock
);
}

public function testCheckCredentialsActionBadCredentials()
Expand Down

0 comments on commit 0b410fb

Please sign in to comment.