Skip to content

Commit 6ae2c5b

Browse files
authored
Merge branch 'develop' into CD-develop
2 parents 1f834d2 + cae669a commit 6ae2c5b

File tree

8 files changed

+70
-54
lines changed

8 files changed

+70
-54
lines changed

dev/tests/static/Magento/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
6868
$phpcsFile->addError($error, $return, 'MissingReturnType');
6969
} else {
7070
// Support both a return type and a description.
71-
$split = preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\a-z0-9\[\]]+))*)( .*)?`i', $content, $returnParts);
71+
preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\a-z0-9\[\]]+))*)( .*)?`i', $content, $returnParts);
7272
if (isset($returnParts[1]) === false) {
7373
return;
7474
}
@@ -78,7 +78,7 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
7878
// Check return type (can be multiple, separated by '|').
7979
$typeNames = explode('|', $returnType);
8080
$suggestedNames = array();
81-
foreach ($typeNames as $i => $typeName) {
81+
foreach ($typeNames as $typeName) {
8282
$suggestedName = Common::suggestType($typeName);
8383
if (in_array($suggestedName, $suggestedNames) === false) {
8484
$suggestedNames[] = $suggestedName;

etc/config/.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#*** Set the base URL for your Magento instance ***#
55
MAGENTO_BASE_URL=http://devdocs.magento.com/
66

7+
#*** Uncomment if you are running Admin Panel on separate domain (used with MAGENTO_BACKEND_NAME) ***#
8+
# MAGENTO_BACKEND_BASE_HOST=http://admin.example.com/
9+
710
#*** Set the Admin Username and Password for your Magento instance ***#
811
MAGENTO_BACKEND_NAME=admin
912
MAGENTO_ADMIN_USERNAME=admin
@@ -23,8 +26,9 @@ MAGENTO_ADMIN_PASSWORD=123123q
2326
BROWSER=chrome
2427

2528
#*** Uncomment and set host & port if your dev environment needs different value other than MAGENTO_BASE_URL for Rest API Requests ***#
26-
#MAGENTO_RESTAPI_SERVER_HOST=
27-
#MAGENTO_RESTAPI_SERVER_PORT=
29+
#MAGENTO_RESTAPI_SERVER_HOST=restapi.magento.com
30+
#MAGENTO_RESTAPI_SERVER_PORT=8080
31+
#MAGENTO_RESTAPI_SERVER_PROTOCOL=https
2832

2933
#*** Uncomment these properties to set up a dev environment with symlinked projects ***#
3034
#TESTS_BP=

etc/config/functional.suite.dist.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ modules:
2020
config:
2121
\Magento\FunctionalTestingFramework\Module\MagentoWebDriver:
2222
url: "%MAGENTO_BASE_URL%"
23+
backend_url: "%MAGENTO_BACKEND_BASE_URL%"
2324
backend_name: "%MAGENTO_BACKEND_NAME%"
2425
browser: 'chrome'
2526
restart: true

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AbstractExecutor.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,18 @@
1414
abstract class AbstractExecutor implements CurlInterface
1515
{
1616
/**
17-
* Base url.
17+
* Returns Magento base URL. Used as a fallback for other services (eg. WebApi, Backend)
1818
*
1919
* @var string
2020
*/
2121
protected static $baseUrl = null;
2222

2323
/**
24-
* Resolve base url.
25-
*
26-
* @return void
24+
* Returns base URL for Magento instance
25+
* @return string
2726
*/
28-
protected static function resolveBaseUrl()
27+
public function getBaseUrl(): string
2928
{
30-
31-
if ((getenv('MAGENTO_RESTAPI_SERVER_HOST') !== false)
32-
&& (getenv('MAGENTO_RESTAPI_SERVER_HOST') !== '') ) {
33-
self::$baseUrl = getenv('MAGENTO_RESTAPI_SERVER_HOST');
34-
} else {
35-
self::$baseUrl = getenv('MAGENTO_BASE_URL');
36-
}
37-
38-
if ((getenv('MAGENTO_RESTAPI_SERVER_PORT') !== false)
39-
&& (getenv('MAGENTO_RESTAPI_SERVER_PORT') !== '')) {
40-
self::$baseUrl .= ':' . getenv('MAGENTO_RESTAPI_SERVER_PORT');
41-
}
42-
43-
self::$baseUrl = rtrim(self::$baseUrl, '/') . '/';
29+
return getenv('MAGENTO_BASE_URL');
4430
}
4531
}

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,11 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
3737
private $response;
3838

3939
/**
40-
* Should executor remove backend_name from api url
40+
* Flag describes whether the request is to Magento Base URL, removes backend_name from api url
4141
* @var boolean
4242
*/
4343
private $removeBackend;
4444

45-
/**
46-
* Backend url.
47-
*
48-
* @var string
49-
*/
50-
private static $adminUrl;
51-
5245
/**
5346
* Constructor.
5447
* @param boolean $removeBackend
@@ -58,15 +51,21 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
5851
*/
5952
public function __construct($removeBackend)
6053
{
61-
if (!isset(parent::$baseUrl)) {
62-
parent::resolveBaseUrl();
63-
}
64-
self::$adminUrl = parent::$baseUrl . getenv('MAGENTO_BACKEND_NAME') . '/';
6554
$this->removeBackend = $removeBackend;
6655
$this->transport = new CurlTransport();
6756
$this->authorize();
6857
}
6958

59+
/**
60+
* Returns base URL for Magento backend instance
61+
* @return string
62+
*/
63+
public function getBaseUrl(): string
64+
{
65+
$backendHost = getenv('MAGENTO_BACKEND_BASE_URL') ?: parent::getBaseUrl();
66+
return $backendHost . getenv('MAGENTO_BACKEND_NAME') . '/';
67+
}
68+
7069
/**
7170
* Authorize admin on backend.
7271
*
@@ -76,11 +75,11 @@ public function __construct($removeBackend)
7675
private function authorize()
7776
{
7877
// Perform GET to backend url so form_key is set
79-
$this->transport->write(self::$adminUrl, [], CurlInterface::GET);
78+
$this->transport->write($this->getBaseUrl(), [], CurlInterface::GET);
8079
$this->read();
8180

8281
// Authenticate admin user
83-
$authUrl = self::$adminUrl . 'admin/auth/login/';
82+
$authUrl = $this->getBaseUrl() . 'admin/auth/login/';
8483
$data = [
8584
'login[username]' => getenv('MAGENTO_ADMIN_USERNAME'),
8685
'login[password]' => getenv('MAGENTO_ADMIN_PASSWORD'),
@@ -119,10 +118,10 @@ private function setFormKey()
119118
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
120119
{
121120
$url = ltrim($url, "/");
122-
$apiUrl = self::$adminUrl . $url;
121+
$apiUrl = $this->getBaseUrl() . $url;
123122

124123
if ($this->removeBackend) {
125-
$apiUrl = parent::$baseUrl . $url;
124+
$apiUrl = parent::getBaseUrl() . $url;
126125
}
127126

128127
if ($this->formKey) {

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/FrontendExecutor.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ class FrontendExecutor extends AbstractExecutor implements CurlInterface
6767
*/
6868
public function __construct($customerEmail, $customerPassWord)
6969
{
70-
if (!isset(parent::$baseUrl)) {
71-
parent::resolveBaseUrl();
72-
}
7370
$this->transport = new CurlTransport();
7471
$this->customerEmail = $customerEmail;
7572
$this->customerPassword = $customerPassWord;
@@ -84,11 +81,11 @@ public function __construct($customerEmail, $customerPassWord)
8481
*/
8582
private function authorize()
8683
{
87-
$url = parent::$baseUrl . 'customer/account/login/';
84+
$url = $this->getBaseUrl() . 'customer/account/login/';
8885
$this->transport->write($url);
8986
$this->read();
9087

91-
$url = parent::$baseUrl . 'customer/account/loginPost/';
88+
$url = $this->getBaseUrl() . 'customer/account/loginPost/';
9289
$data = [
9390
'login[username]' => $this->customerEmail,
9491
'login[password]' => $this->customerPassword,
@@ -146,7 +143,7 @@ public function write($url, $data = [], $method = CurlInterface::POST, $headers
146143
if (isset($data['customer_password'])) {
147144
unset($data['customer_password']);
148145
}
149-
$apiUrl = parent::$baseUrl . $url;
146+
$apiUrl = $this->getBaseUrl() . $url;
150147
if ($this->formKey) {
151148
$data['form_key'] = $this->formKey;
152149
} else {

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/WebapiExecutor.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,34 @@ class WebapiExecutor extends AbstractExecutor implements CurlInterface
5959
*/
6060
public function __construct($storeCode = null)
6161
{
62-
if (!isset(parent::$baseUrl)) {
63-
parent::resolveBaseUrl();
64-
}
65-
6662
$this->storeCode = $storeCode;
6763
$this->transport = new CurlTransport();
6864
$this->authorize();
6965
}
7066

67+
/**
68+
* Returns base URL for Magento Web API instance
69+
* @return string
70+
*/
71+
public function getBaseUrl(): string
72+
{
73+
$baseUrl = parent::getBaseUrl();
74+
75+
$webapiHost = getenv('MAGENTO_RESTAPI_SERVER_HOST');
76+
$webapiPort = getenv("MAGENTO_RESTAPI_SERVER_PORT");
77+
$webapiProtocol = getenv("MAGENTO_RESTAPI_SERVER_PROTOCOL");
78+
79+
if ($webapiHost) {
80+
$baseUrl = sprintf('%s://%s/', $webapiProtocol, $webapiHost);
81+
}
82+
83+
if ($webapiPort) {
84+
$baseUrl = rtrim($baseUrl, '/') . ':' . $webapiPort . '/';
85+
}
86+
87+
return $baseUrl;
88+
}
89+
7190
/**
7291
* Returns the authorization token needed for some requests via REST call.
7392
*
@@ -152,11 +171,11 @@ public function close()
152171
*/
153172
public function getFormattedUrl($resource)
154173
{
155-
$urlResult = parent::$baseUrl . 'rest/';
174+
$urlResult = $this->getBaseUrl() . 'rest/';
156175
if ($this->storeCode != null) {
157176
$urlResult .= $this->storeCode . "/";
158177
}
159-
$urlResult.= trim($resource, "/");
178+
$urlResult .= trim($resource, "/");
160179
return $urlResult;
161180
}
162181
}

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,18 @@ protected function getAdminToken()
396396
{
397397
$login = $_ENV['MAGENTO_ADMIN_USERNAME'] ?? null;
398398
$password = $_ENV['MAGENTO_ADMIN_PASSWORD'] ?? null;
399-
if (!$login || !$password || !isset($_ENV['MAGENTO_BASE_URL'])) {
399+
if (!$login || !$password || !$this->getBackendUrl()) {
400400
$message = "Cannot retrieve API token without credentials and base url, please fill out .env.";
401401
$context = [
402402
"MAGENTO_BASE_URL" => getenv("MAGENTO_BASE_URL"),
403+
"MAGENTO_BACKEND_BASE_URL" => getenv("MAGENTO_BACKEND_BASE_URL"),
403404
"MAGENTO_ADMIN_USERNAME" => getenv("MAGENTO_ADMIN_USERNAME"),
404405
"MAGENTO_ADMIN_PASSWORD" => getenv("MAGENTO_ADMIN_PASSWORD"),
405406
];
406407
throw new TestFrameworkException($message, $context);
407408
}
408409

409-
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->adminTokenUrl;
410+
$url = ConfigSanitizerUtil::sanitizeUrl($this->getBackendUrl()) . $this->adminTokenUrl;
410411
$data = [
411412
'username' => $login,
412413
'password' => $password
@@ -428,7 +429,7 @@ protected function getAdminToken()
428429

429430
if ($responseCode !== 200) {
430431
if ($responseCode == 0) {
431-
$details = "Could not find Magento Instance at given MAGENTO_BASE_URL";
432+
$details = "Could not find Magento Backend Instance at MAGENTO_BACKEND_BASE_URL or MAGENTO_BASE_URL";
432433
} else {
433434
$details = $responseCode . " " . Response::$statusTexts[$responseCode];
434435
}
@@ -565,4 +566,13 @@ private function getRegisteredModuleList()
565566
}
566567
return [];
567568
}
569+
570+
/**
571+
* Returns custom Backend URL if set, fallback to Magento Base URL
572+
* @return string|null
573+
*/
574+
private function getBackendUrl()
575+
{
576+
return getenv('MAGENTO_BACKEND_BASE_URL') ?: getenv('MAGENTO_BASE_URL');
577+
}
568578
}

0 commit comments

Comments
 (0)