function CommandUnishTestCase::drush

8.0.x CommandUnishTestCase.php CommandUnishTestCase::drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array())
7.x CommandUnishTestCase.php CommandUnishTestCase::drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array())
master CommandUnishTestCase.php CommandUnishTestCase::drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array())

Invoke drush in via execute().

Parameters

command: A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'.

args: Command arguments.

$options: An associative array containing options.

$site_specification: A site alias or site specification. Include the '@' at start of a site alias.

$cd: A directory to change into before executing.

$expected_return: The expected exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.

$suffix: Any code to append to the command. For example, redirection like 2>&1.

Return value

integer An exit code.

105 calls to CommandUnishTestCase::drush()
archiveDumpCase::archiveDump in tests/archiveDumpTest.php
Install a site and dump it to an archive.
archiveDumpCase::testArchiveRestore in tests/archiveDumpTest.php
Test archive-restore.
archiveDumpCase::testArchiveRestoreNoCore in tests/archiveDumpTest.php
Test archive-restore for a site archive (--no-core).
backendCase::testBackendFunctionResult in tests/backendTest.php
Covers the following target responsibilities.
backendCase::testBackendInvokeMultiple in tests/backendTest.php
Covers the following target responsibilities.

... See full list

File

tests/Unish/CommandUnishTestCase.php, line 228

Namespace

Unish

Class

CommandUnishTestCase

Code

function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array()) {
  $global_option_list = array(
    'simulate',
    'root',
    'uri',
    'include',
    'config',
    'alias-path',
    'ssh-options',
    'backend',
  );
  $hide_stderr = FALSE;
  $cmd[] = UNISH_DRUSH;

  // insert global options
  foreach ($options as $key => $value) {
    if (in_array($key, $global_option_list)) {
      unset($options[$key]);
      if ($key == 'backend') {
        $hide_stderr = TRUE;
        $value = NULL;
      }
      if (!isset($value)) {
        $cmd[] = "--$key";
      }
      else {
        $cmd[] = "--$key=" . self::escapeshellarg($value);
      }
    }
  }

  if ($level = $this->log_level()) {
    $cmd[] = '--' . $level;
  }
  $cmd[] = "--nocolor";

  // Insert code coverage argument before command, in order for it to be
  // parsed as a global option. This matters for commands like ssh and rsync
  // where options after the command are passed along to external commands.
  $result = $this->getTestResultObject();
  if ($result->getCollectCodeCoverageInformation()) {
    $coverage_file = tempnam(UNISH_TMP, 'drush_coverage');
    if ($coverage_file) {
      $cmd[] = "--drush-coverage=" . $coverage_file;
    }
  }

  // insert site specification and drush command
  $cmd[] = empty($site_specification) ? NULL : self::escapeshellarg($site_specification);
  $cmd[] = $command;

  // insert drush command arguments
  foreach ($args as $arg) {
    $cmd[] = self::escapeshellarg($arg);
  }
  // insert drush command options
  foreach ($options as $key => $value) {
    if (!isset($value)) {
      $cmd[] = "--$key";
    }
    else {
      $cmd[] = "--$key=" . self::escapeshellarg($value);
    }
  }

  $cmd[] = $suffix;
  if ($hide_stderr) {
    $cmd[] = '2>/dev/null';
  }
  $exec = array_filter($cmd, 'strlen'); // Remove NULLs
  // set sendmail_path to 'true' to disable any outgoing emails
  // that tests might cause Drupal to send.
  $php_options = (array_key_exists('PHP_OPTIONS', $env)) ? $env['PHP_OPTIONS'] . " " : "";
  $env['PHP_OPTIONS'] = "${php_options}-d sendmail_path='true'";
  $return = $this->execute(implode(' ', $exec), $expected_return, $cd, $env);

  // Save code coverage information.
  if (!empty($coverage_file)) {
    $data = unserialize(file_get_contents($coverage_file));
    unlink($coverage_file);
    // Save for appending after the test finishes.
    $this->coverage_data[] = $data;
  }

  return $return;
}