commandTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class commandCase extends Drush_TestCase {
  3. public function testInvoke() {
  4. $expected = array(
  5. 'unit_drush_init',
  6. 'drush_unit_invoke_init',
  7. 'drush_unit_invoke_validate',
  8. 'drush_unit_pre_unit_invoke',
  9. 'drush_unit_invoke',
  10. 'drush_unit_post_unit_invoke',
  11. 'drush_unit_post_unit_invoke_rollback',
  12. 'drush_unit_pre_unit_invoke_rollback',
  13. 'drush_unit_invoke_validate_rollback',
  14. );
  15. // We expect a return code of 1 so just call execute() directly.
  16. $exec = sprintf('%s unit-invoke --include=%s', UNISH_DRUSH, self::escapeshellarg(dirname(__FILE__)));
  17. $this->execute($exec, self::EXIT_ERROR);
  18. $called = json_decode($this->getOutput());
  19. $this->assertSame($expected, $called);
  20. }
  21. /*
  22. * Assert that $command has interesting properties. Reference command by
  23. * it's alias (dl) to assure that those aliases are built as expected.
  24. */
  25. public function testGetCommands() {
  26. $eval = '$commands = drush_get_commands();';
  27. $eval .= 'print json_encode($commands[\'dl\'])';
  28. $this->drush('php-eval', array($eval));
  29. $command = json_decode($this->getOutput());
  30. $this->assertEquals('dl', current($command->aliases));
  31. $this->assertEquals('download', current($command->{'deprecated-aliases'}));
  32. $this->assertObjectHasAttribute('version_control', $command->engines);
  33. $this->assertObjectHasAttribute('package_handler', $command->engines);
  34. $this->assertEquals('pm-download', $command->command);
  35. $this->assertEquals('pm', $command->commandfile);
  36. $this->assertEquals('drush_command', $command->callback);
  37. $this->assertObjectHasAttribute('examples', $command->sections);
  38. $this->assertTrue($command->is_alias);
  39. }
  40. /*
  41. * Assert that minimum bootstrap phase is honored.
  42. *
  43. * Not testing dependency on a module since that requires an installed Drupal.
  44. * Too slow for little benefit.
  45. */
  46. public function testRequirementBootstrapPhase() {
  47. // Assure that core-cron fails when run outside of a Drupal site.
  48. $return = $this->execute(UNISH_DRUSH . ' core-cron --quiet', self::EXIT_ERROR);
  49. }
  50. }