|
21 | 21 | use Magento\FunctionalTestingFramework\Util\ConfigSanitizerUtil; |
22 | 22 | use Yandex\Allure\Adapter\AllureException; |
23 | 23 | use Magento\FunctionalTestingFramework\Util\Protocol\CurlTransport; |
24 | | -use Symfony\Component\Process\Process; |
25 | 24 | use Yandex\Allure\Adapter\Support\AttachmentSupport; |
26 | 25 | use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; |
27 | 26 | use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; |
@@ -520,13 +519,35 @@ public function scrollToTopOfPage() |
520 | 519 | */ |
521 | 520 | public function magentoCLI($command, $timeout = null, $arguments = null) |
522 | 521 | { |
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; |
530 | 551 | } |
531 | 552 |
|
532 | 553 | /** |
@@ -834,74 +855,4 @@ public function makeScreenshot($name = null) |
834 | 855 | $this->debug("Screenshot saved to $screenName"); |
835 | 856 | AllureHelper::addAttachmentToCurrentStep($screenName, 'Screenshot'); |
836 | 857 | } |
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 | | - } |
907 | 858 | } |
0 commit comments