Skip to content

Commit f074ae7

Browse files
committed
MAGETWO-51505: Improve Component Manager workflow
- CR fixes.
1 parent f99ba28 commit f074ae7

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

setup/src/Magento/Setup/Controller/Marketplace.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function saveAuthJsonAction()
6161
try {
6262
$userName = isset($params['username']) ? $params['username'] : '';
6363
$password = isset($params['password']) ? $params['password'] : '';
64-
$isValid = $this->packagesAuth->checkCredentialsAction($userName, $password);
64+
$isValid = $this->packagesAuth->checkCredentials($userName, $password);
6565
$isValid = json_decode($isValid, true);
6666
if ($isValid['success'] === true && $this->packagesAuth->saveAuthJson($userName, $password)) {
6767
$this->packagesData->syncPackagesData();
@@ -84,10 +84,7 @@ public function checkAuthAction()
8484
try {
8585
$authDataJson = $this->packagesAuth->getAuthJsonData();
8686
if ($authDataJson) {
87-
$isValid = $this->packagesAuth->checkCredentialsAction(
88-
$authDataJson['username'],
89-
$authDataJson['password']
90-
);
87+
$isValid = $this->packagesAuth->checkCredentials($authDataJson['username'], $authDataJson['password']);
9188
$isValid = json_decode($isValid, true);
9289
if ($isValid['success'] === true) {
9390
return new JsonModel(['success' => true, 'data' => [

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Zend\View\Model\JsonModel;
1111

12+
/**
13+
* Class PackagesAuth, checks, saves and removes auth details related to packages.
14+
*/
1215
class PackagesAuth
1316
{
1417
/**#@+
@@ -17,12 +20,14 @@ class PackagesAuth
1720
const KEY_HTTPBASIC = 'http-basic';
1821
const KEY_USERNAME = 'username';
1922
const KEY_PASSWORD = 'password';
23+
/**#@-/
2024
2125
/**#@+
2226
* Filenames for auth and package info
2327
*/
2428
const PATH_TO_AUTH_FILE = 'auth.json';
2529
const PATH_TO_PACKAGES_FILE = 'packages.json';
30+
/**#@-/
2631
2732
/**
2833
* @var \Zend\ServiceManager\ServiceLocatorInterface
@@ -81,7 +86,7 @@ public function getCredentialBaseUrl()
8186
* @param string $secretKey
8287
* @return string
8388
*/
84-
public function checkCredentialsAction($token, $secretKey)
89+
public function checkCredentials($token, $secretKey)
8590
{
8691
$serviceUrl = $this->getPackagesJsonUrl();
8792
$this->curlClient->setCredentials($token, $secretKey);

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77
namespace Magento\Setup\Model;
88

99
/**
10-
* Class SyncPackages returns system package and available for update versions
10+
* Class PackagesData returns system packages and available for update versions
1111
*/
1212
class PackagesData
1313
{
14-
/**#@+
15-
* Composer command
16-
*/
17-
const COMPOSER_SHOW = 'show';
18-
/**#@-*/
19-
2014
/**#@+
2115
* Composer command params and options
2216
*/
17+
const COMPOSER_SHOW = 'show';
2318
const PARAM_COMMAND = 'command';
2419
const PARAM_PACKAGE = 'package';
2520
const PARAM_AVAILABLE = '--available';
21+
/**#@-*/
2622

2723
/**
2824
* @var \Magento\Framework\Composer\ComposerInformation
@@ -59,7 +55,6 @@ class PackagesData
5955
*
6056
* @param \Magento\Framework\Composer\ComposerInformation $composerInformation,
6157
* @param \Magento\Setup\Model\DateTime\TimeZoneProvider $timeZoneProvider,
62-
* @param \Magento\Framework\HTTP\Client\Curl $curl,
6358
* @param \Magento\Setup\Model\PackagesAuth $packagesAuth,
6459
* @param \Magento\Framework\Filesystem $filesystem,
6560
* @param \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider
@@ -368,13 +363,9 @@ private function getPackageAvailableVersions($package)
368363
count($magentoRepositories) === 1
369364
&& strpos($magentoRepositories[0], $this->packagesAuth->getCredentialBaseUrl())
370365
) {
371-
$packagesJsonData = [];
372-
if (empty($this->packagesJsonData)) {
373-
$this->packagesJsonData = $this->getPackagesJson();
374-
}
375-
376-
if ($this->packagesJsonData) {
377-
$packagesJsonData = json_decode($this->packagesJsonData, true);
366+
$packagesJsonData = $this->getPackagesJson();
367+
if ($packagesJsonData) {
368+
$packagesJsonData = json_decode($packagesJsonData, true);
378369
} else {
379370
$packagesJsonData['packages'] = [];
380371
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function testCheckCredentialsActionBadCredentials()
5050
$this->curl->expects($this->once())->method('setCredentials')->with('username', 'password');
5151
$this->curl->expects($this->once())->method('getStatus');
5252
$expectedValue = '{"success":false,"message":"Bad credentials"}';
53-
$returnValue = $this->packagesAuth->checkCredentialsAction('username', 'password');
53+
$returnValue = $this->packagesAuth->checkCredentials('username', 'password');
5454
$this->assertSame($expectedValue, $returnValue);
5555
}
5656

57-
public function testCheckCredentialsAction()
57+
public function testCheckCredentials()
5858
{
5959
$this->curl->expects($this->once())->method('setCredentials')->with('username', 'password');
6060
$this->curl->expects($this->once())->method('getStatus')->willReturn(200);
@@ -65,7 +65,7 @@ public function testCheckCredentialsAction()
6565
->method('writeFile')
6666
->with(PackagesAuth::PATH_TO_PACKAGES_FILE, "{'someJson'}");
6767
$expectedValue = '{"success":true}';
68-
$returnValue = $this->packagesAuth->checkCredentialsAction('username', 'password');
68+
$returnValue = $this->packagesAuth->checkCredentials('username', 'password');
6969
$this->assertSame($expectedValue, $returnValue);
7070
}
7171

@@ -78,7 +78,7 @@ public function testCheckCredentialsActionWithException()
7878
$this->curl->expects($this->never())->method('getBody')->willReturn("{'someJson}");
7979

8080
$expectedValue = '{"success":false,"message":"Test error"}';
81-
$returnValue = $this->packagesAuth->checkCredentialsAction('username', 'password');
81+
$returnValue = $this->packagesAuth->checkCredentials('username', 'password');
8282
$this->assertSame($expectedValue, $returnValue);
8383
}
8484

0 commit comments

Comments
 (0)