Skip to content

Commit 580d6dc

Browse files
authored
Merge pull request #519 from magento/MQE-1902-2
MQE-1902: Running bin/magento from MagentoWebDriver causing timeout i…
2 parents 94737d1 + fa8e51b commit 580d6dc

File tree

1 file changed

+29
-78
lines changed

1 file changed

+29
-78
lines changed

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil;
2222
use Yandex\Allure\Adapter\AllureException;
2323
use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport;
24-
use Symfony\Component\Process\Process;
2524
use Yandex\Allure\Adapter\Support\AttachmentSupport;
2625
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
2726
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
@@ -520,13 +519,35 @@ public function scrollToTopOfPage()
520519
*/
521520
public function magentoCLI($command, $timeout = null, $arguments = null)
522521
{
523-
return $this->curlExecMagentoCLI($command, $timeout, $arguments);
524-
//TODO: calling bin/magento from pipeline is timing out, needs investigation (ref: MQE-1774)
525-
// try {
526-
// return $this->shellExecMagentoCLI($command, $arguments);
527-
// } catch (\Exception $exception) {
528-
// return $this->curlExecMagentoCLI($command, $arguments);
529-
// }
522+
// Remove index.php if it's present in url
523+
$baseUrl = rtrim(
524+
str_replace('index.php', '', rtrim($this->config['url'], '/')),
525+
'/'
526+
);
527+
528+
$apiURL = UrlFormatter::format(
529+
$baseUrl . '/' . ltrim(getenv('MAGENTO_CLI_COMMAND_PATH'), '/'),
530+
false
531+
);
532+
533+
$restExecutor = new WebapiExecutor();
534+
$executor = new CurlTransport();
535+
$executor->write(
536+
$apiURL,
537+
[
538+
'token' => $restExecutor->getAuthToken(),
539+
getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command,
540+
'arguments' => $arguments,
541+
'timeout' => $timeout,
542+
],
543+
CurlInterface::POST,
544+
[]
545+
);
546+
$response = $executor->read();
547+
$restExecutor->close();
548+
$executor->close();
549+
550+
return $response;
530551
}
531552

532553
/**
@@ -834,74 +855,4 @@ public function makeScreenshot($name = null)
834855
$this->debug("Screenshot saved to $screenName");
835856
AllureHelper::addAttachmentToCurrentStep($screenName, 'Screenshot');
836857
}
837-
838-
/**
839-
* Takes given $command and executes it against bin/magento executable. Returns stdout output from the command.
840-
*
841-
* @param string $command
842-
* @param integer $timeout
843-
* @param string $arguments
844-
*
845-
* @throws \RuntimeException
846-
* @return string
847-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
848-
*/
849-
private function shellExecMagentoCLI($command, $timeout, $arguments): string
850-
{
851-
$php = PHP_BINDIR ? PHP_BINDIR . DIRECTORY_SEPARATOR. 'php' : 'php';
852-
$binMagento = realpath(MAGENTO_BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento');
853-
$command = $php . ' -f ' . $binMagento . ' ' . $command . ' ' . $arguments;
854-
$process = new Process(escapeshellcmd($command), MAGENTO_BP);
855-
$process->setIdleTimeout($timeout);
856-
$process->setTimeout(0);
857-
$exitCode = $process->run();
858-
if ($exitCode !== 0) {
859-
throw new \RuntimeException($process->getErrorOutput());
860-
}
861-
862-
return $process->getOutput();
863-
}
864-
865-
/**
866-
* Takes given $command and executes it against exposed MTF CLI entry point. Returns response from server.
867-
*
868-
* @param string $command
869-
* @param integer $timeout
870-
* @param string $arguments
871-
*
872-
* @return string
873-
* @throws TestFrameworkException
874-
*/
875-
private function curlExecMagentoCLI($command, $timeout, $arguments): string
876-
{
877-
// Remove index.php if it's present in url
878-
$baseUrl = rtrim(
879-
str_replace('index.php', '', rtrim($this->config['url'], '/')),
880-
'/'
881-
);
882-
883-
$apiURL = UrlFormatter::format(
884-
$baseUrl . '/' . ltrim(getenv('MAGENTO_CLI_COMMAND_PATH'), '/'),
885-
false
886-
);
887-
888-
$restExecutor = new WebapiExecutor();
889-
$executor = new CurlTransport();
890-
$executor->write(
891-
$apiURL,
892-
[
893-
'token' => $restExecutor->getAuthToken(),
894-
getenv('MAGENTO_CLI_COMMAND_PARAMETER') => $command,
895-
'arguments' => $arguments,
896-
'timeout' => $timeout,
897-
],
898-
CurlInterface::POST,
899-
[]
900-
);
901-
$response = $executor->read();
902-
$restExecutor->close();
903-
$executor->close();
904-
905-
return $response;
906-
}
907858
}

0 commit comments

Comments
 (0)