Cli.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Mtf\Util\Command;
  7. use Magento\Mtf\Util\Protocol\CurlInterface;
  8. use Magento\Mtf\Util\Protocol\CurlTransport;
  9. /**
  10. * Perform bin/magento commands from command line for functional tests executions.
  11. */
  12. class Cli
  13. {
  14. /**
  15. * Url to command.php.
  16. */
  17. const URL = 'dev/tests/functional/utils/command.php';
  18. /**
  19. * Curl transport protocol.
  20. *
  21. * @var CurlTransport
  22. */
  23. private $transport;
  24. /**
  25. * @param CurlTransport $transport
  26. */
  27. public function __construct(CurlTransport $transport)
  28. {
  29. $this->transport = $transport;
  30. }
  31. /**
  32. * Run command.
  33. *
  34. * @param string $command
  35. * @param array $options [optional]
  36. * @return void
  37. */
  38. public function execute($command, $options = [])
  39. {
  40. $curl = $this->transport;
  41. $curl->write($this->prepareUrl($command, $options), [], CurlInterface::GET);
  42. $curl->read();
  43. $curl->close();
  44. }
  45. /**
  46. * Prepare url.
  47. *
  48. * @param string $command
  49. * @param array $options [optional]
  50. * @return string
  51. */
  52. private function prepareUrl($command, $options = [])
  53. {
  54. $command .= ' ' . implode(' ', $options);
  55. return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
  56. }
  57. }