function CommandUnishTestCase::execute

8.0.x CommandUnishTestCase.php CommandUnishTestCase::execute($command, $expected_return = self::EXIT_SUCCESS, $cd = NULL, $env = array())
7.x CommandUnishTestCase.php CommandUnishTestCase::execute($command, $expected_return = self::EXIT_SUCCESS, $cd = NULL, $env = array())
master CommandUnishTestCase.php CommandUnishTestCase::execute($command, $expected_return = self::EXIT_SUCCESS, $cd = NULL, $env = NULL, $input = NULL)

Actually runs the command.

Parameters

string $command: The actual command line to run.

integer $expected_return: The return code to expect

sting cd: The directory to run the command in.

array $env: Extra environment variables

Return value

integer Exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.

11 calls to CommandUnishTestCase::execute()
archiveDumpCase::testArchiveDump in tests/archiveDumpTest.php
Test if tarball generated by archive-dump looks right.
archiveDumpCase::unTar in tests/archiveDumpTest.php
Untar an archive and return the path to the untarred folder.
backendCase::testOrigin in tests/backendTest.php
Covers the following origin responsibilities.
backendCase::testRealtimeOutput in tests/backendTest.php
Covers the following target responsibilities.
backendCase::testTarget in tests/backendTest.php
Covers the following target responsibilities.

... See full list

File

tests/Unish/CommandUnishTestCase.php, line 164

Namespace

Unish

Class

CommandUnishTestCase

Code

function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = NULL, $env = array()) {
  $return = 1;
  $this->tick();

  // Apply the environment variables we need for our test to the head of the
  // command. Process does have an $env argument, but it replaces the entire
  // environment with the one given. This *could* be used for ensuring the
  // test ran with a clean environment, but it also makes tests fail hard on
  // Travis, for unknown reasons.
  // @see https://github.com/drush-ops/drush/pull/646
  $prefix = '';
  foreach ($env as $env_name => $env_value) {
    $prefix .= $env_name . '=' . self::escapeshellarg($env_value) . ' ';
  }
  $this->log("Executing: $prefix$command", 'warning');

  try {
    // Process uses a default timeout of 60 seconds, set it to 0 (none).
    $this->process = new Process($prefix . $command, $cd, NULL, NULL, 0);
    if (!getenv('UNISH_NO_TIMEOUTS')) {
      $this->process->setTimeout($this->timeout)->setIdleTimeout($this->idleTimeout);
    }
    $return = $this->process->run();
    if ($expected_return !== $return) {
      $message = 'Unexpected exit code ' . $return . ' (expected ' . $expected_return . ") for command:\n" . $command;
      throw new UnishProcessFailedError($message, $this->process);
    }
    // Reset timeouts to default.
    $this->timeout = $this->defaultTimeout;
    $this->idleTimeout = $this->defaultIdleTimeout;
    return $return;
  }
  catch (ProcessTimedOutException $e) {
    if ($e->isGeneralTimeout()) {
      $message = 'Command runtime exceeded ' . $this->timeout . " seconds:\n" . $command;
    }
    else {
      $message = 'Command had no output for ' . $this->idleTimeout . " seconds:\n" . $command;
    }
    throw new UnishProcessFailedError($message, $this->process);
  }
}