function Drush_CommandTestCase::drush

6.x drush_testcase.inc Drush_CommandTestCase::drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL, $expected_return = self::EXIT_SUCCESS, $suffix = NULL, $env = array())
5.x drush_testcase.inc Drush_CommandTestCase::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.

76 calls to Drush_CommandTestCase::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/drush_testcase.inc, line 356

Class

Drush_CommandTestCase

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',
  );
  // insert "cd ... ; drush"
  $cmd[] = $cd ? sprintf('cd %s &&', self::escapeshellarg($cd)) : NULL;
  $cmd[] = UNISH_DRUSH;

  // insert global options
  foreach ($options as $key => $value) {
    if (in_array($key, $global_option_list)) {
      unset($options[$key]);
      if (is_null($value)) {
        $cmd[] = "--$key";
      }
      else {
        $cmd[] = "--$key=" . self::escapeshellarg($value);
      }
    }
  }

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

  // 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 (is_null($value)) {
      $cmd[] = "--$key";
    }
    else {
      $cmd[] = "--$key=" . self::escapeshellarg($value);
    }
  }
  $cmd[] = $suffix;
  $exec = array_filter($cmd, 'strlen'); // Remove NULLs
  return $this->execute(implode(' ', $exec), $expected_return, $env);
}