class commandCase

  1. 8.0.x tests/commandTest.php commandCase
  2. 6.x tests/commandTest.php commandCase
  3. 7.x tests/commandTest.php commandCase
  4. 4.x tests/commandTest.php commandCase
  5. 5.x tests/commandTest.php commandCase
  6. master tests/commandTest.php commandCase

@group base

Namespace

Unish

Hierarchy

Expanded class hierarchy of commandCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
commandCase::testDisabledModule public function Assert that commands in disabled modules are detected.
commandCase::testInvoke public function
commandCase::testMissingCommandCallback public function Assert that errors are thrown for commands with missing callbacks.
commandCase::testMissingDrushDependency public function Assert that commands depending on unknown commandfiles are detected.
commandCase::testRequirementBootstrapPhase public function Assert that minimum bootstrap phase is honored.
commandCase::testUnknownOptions public function Assert that unknown options are caught and flagged as errors
CommandUnishTestCase::$coverage_data protected property Code coverage data collected during a single test.
CommandUnishTestCase::$defaultIdleTimeout private property Default idle timeout for commands.
CommandUnishTestCase::$defaultTimeout private property Default timeout for commands.
CommandUnishTestCase::$idleTimeout protected property Idle timeouts for commands.
CommandUnishTestCase::$process private property Process of last executed command.
CommandUnishTestCase::$timeout protected property Timeout for command.
CommandUnishTestCase::assertLogHasMessage function Ensure that an expected log message appears in the Drush log.
CommandUnishTestCase::drush function Invoke drush in via execute().
CommandUnishTestCase::drush_major_version function
CommandUnishTestCase::execute function Actually runs the command.
CommandUnishTestCase::EXIT_ERROR constant
CommandUnishTestCase::EXIT_SUCCESS constant
CommandUnishTestCase::getErrorOutput function Accessor for the last stderr output, trimmed.
CommandUnishTestCase::getErrorOutputAsList function Accessor for the last stderr output, rtrimmed and split on newlines.
CommandUnishTestCase::getErrorOutputRaw function Accessor for the last stderr output, non-trimmed.
CommandUnishTestCase::getOutput function Accessor for the last output, trimmed.
CommandUnishTestCase::getOutputAsList function Accessor for the last output, rtrimmed and split on newlines.
CommandUnishTestCase::getOutputFromJSON function Accessor for the last output, decoded from json.
CommandUnishTestCase::getOutputRaw function Accessor for the last output, non-trimmed.
CommandUnishTestCase::parse_backend_output function A slightly less functional copy of drush_backend_parse_output().
CommandUnishTestCase::run public function Override the run method, so we can add in our code coverage data after the test has run.
CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT constant
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed. They key is the site name and values are details about each site.
UnishTestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
UnishTestCase::convert_path function Converts a Windows path (dir1\dir2\dir3) into a Unix path (dir1/dir2/dir3). Also converts a cygwin "drive emulation" path (/cygdrive/c/dir1) into a proper drive path, still with Unix slashes (c:/dir1).
UnishTestCase::db_driver function
UnishTestCase::db_url function
UnishTestCase::directory_cache function
UnishTestCase::drupalSitewideDirectory function
UnishTestCase::escapeshellarg public static function
UnishTestCase::fetchInstallDrupal function
UnishTestCase::getSites function
UnishTestCase::get_tar_executable public static function
UnishTestCase::is_windows public static function
UnishTestCase::log function Print a log message to the console.
UnishTestCase::log_level function
UnishTestCase::mkdir public function
UnishTestCase::randomString public function Helper function to generate a random string of arbitrary length.
UnishTestCase::recursive_copy public function
UnishTestCase::setUpBeforeClass public static function Assure that each class starts with an empty sandbox directory and a clean environment - http://drupal.org/node/1103568.
UnishTestCase::setUpDrupal function
UnishTestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
UnishTestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory.
UnishTestCase::tick function Print out a tick mark.
UnishTestCase::unish_file_aliases function Prepare the contents of an aliases file.
UnishTestCase::webroot function
UnishTestCase::writeSiteAlias function
UnishTestCase::_escapeshellarg_windows public static function
UnishTestCase::__construct function

File

tests/commandTest.php, line 8

View source
class commandCase extends CommandUnishTestCase {
  public function testInvoke() {
    $expected = array(
      'unit_drush_init',
      'drush_unit_invoke_init',
      'drush_unit_invoke_validate',
      'drush_unit_pre_unit_invoke',
      'drush_unit_invoke_primary',
      
      // Primary callback is not invoked when command specifies a 'callback'.
      // 'drush_unit_invoke',
      'drush_unit_post_unit_invoke',
      'drush_unit_post_unit_invoke_rollback',
      'drush_unit_pre_unit_invoke_rollback',
      'drush_unit_invoke_validate_rollback',
    );

    $options = array(
      'include' => dirname(__FILE__),
    );
    $this->drush('unit-invoke', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $called = $this->getOutputFromJSON();
    $this->assertSame($expected, $called);
  }

  /**
   * Assert that minimum bootstrap phase is honored.
   *
   * Not testing dependency on a module since that requires an installed Drupal.
   * Too slow for little benefit.
   */
  public function testRequirementBootstrapPhase() {
    // Assure that core-cron fails when run outside of a Drupal site.
    $return = $this->drush('core-cron', array(), array('quiet' => NULL), NULL, NULL, self::EXIT_ERROR);
  }

  /**
   * Assert that unknown options are caught and flagged as errors
   */
  public function testUnknownOptions() {
    // Make sure an ordinary 'version' command works
    $return = $this->drush('version', array(), array('pipe' => NULL));
    // Add an unknown option --magic=1234 and insure it fails
    $return = $this->drush('version', array(), array('pipe' => NULL, 'magic' => 1234), NULL, NULL, self::EXIT_ERROR);
    // Finally, add in a hook that uses hook_drush_help_alter to allow the 'magic' option.
    // We need to run 'drush cc drush' to clear the commandfile cache; otherwise, our include will not be found.
    $include_path = dirname(__FILE__) . '/hooks/magic_help_alter';
    $this->drush('version', array(), array('include' => $include_path, 'pipe' => NULL, 'magic' => '1234', 'strict' => NULL));
  }

  /**
   * Assert that errors are thrown for commands with missing callbacks.
   */
  public function testMissingCommandCallback() {
    $options = array(
      'include' => dirname(__FILE__), // Find unit.drush.inc commandfile. //'show-invoke' => TRUE,
    );
    $this->drush('missing-callback', array(), $options, NULL, NULL, self::EXIT_ERROR);
  }

  /**
   * Assert that commands depending on unknown commandfiles are detected.
   */
  public function testMissingDrushDependency() {
    $options = array(
      'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
      'backend' => NULL, // To obtain and parse the error log.
    );
    $this->drush('unit-drush-dependency', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $parsed = $this->parse_backend_output($this->getOutput());
    $this->assertArrayHasKey("DRUSH_COMMANDFILE_DEPENDENCY_ERROR", $parsed['error_log']);
  }

  /**
   * Assert that commands in disabled modules are detected.
   */
  public function testDisabledModule() {
    $sites = $this->setUpDrupal(1, TRUE);
    $uri = key($sites);
    $root = $this->webroot();
    $options = array(
      'root' => $root,
      'uri' => $uri,
      'cache' => NULL,
    );
    $this->drush('pm-download', array('devel'), $options);
    $options += array(
      'backend' => NULL, // To obtain and parse the error log.
    );
    $this->drush('devel-download', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $parsed = $this->parse_backend_output($this->getOutput());
    $this->assertArrayHasKey("DRUSH_COMMAND_DEPENDENCY_ERROR", $parsed['error_log']);
  }
}