commandTest.php

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

Namespace

Unish

Classes

Namesort descending Description
commandCase @group base

File

tests/commandTest.php
View source
  1. <?php
  2. namespace Unish;
  3. /**
  4. * @group base
  5. */
  6. class commandCase extends CommandUnishTestCase {
  7. public function testInvoke() {
  8. $expected = array(
  9. 'unit_drush_init',
  10. 'drush_unit_invoke_init',
  11. 'drush_unit_invoke_validate',
  12. 'drush_unit_pre_unit_invoke',
  13. 'drush_unit_invoke_primary',
  14. // Primary callback is not invoked when command specifies a 'callback'.
  15. // 'drush_unit_invoke',
  16. 'drush_unit_post_unit_invoke',
  17. 'drush_unit_post_unit_invoke_rollback',
  18. 'drush_unit_pre_unit_invoke_rollback',
  19. 'drush_unit_invoke_validate_rollback',
  20. );
  21. $options = array(
  22. 'include' => dirname(__FILE__),
  23. );
  24. $this->drush('unit-invoke', array(), $options, NULL, NULL, self::EXIT_ERROR);
  25. $called = $this->getOutputFromJSON();
  26. $this->assertSame($expected, $called);
  27. }
  28. /**
  29. * Assert that minimum bootstrap phase is honored.
  30. *
  31. * Not testing dependency on a module since that requires an installed Drupal.
  32. * Too slow for little benefit.
  33. */
  34. public function testRequirementBootstrapPhase() {
  35. // Assure that core-cron fails when run outside of a Drupal site.
  36. $return = $this->drush('core-cron', array(), array('quiet' => NULL), NULL, NULL, self::EXIT_ERROR);
  37. }
  38. /**
  39. * Assert that unknown options are caught and flagged as errors
  40. */
  41. public function testUnknownOptions() {
  42. // Make sure an ordinary 'version' command works
  43. $return = $this->drush('version', array(), array('pipe' => NULL));
  44. // Add an unknown option --magic=1234 and insure it fails
  45. $return = $this->drush('version', array(), array('pipe' => NULL, 'magic' => 1234), NULL, NULL, self::EXIT_ERROR);
  46. // Finally, add in a hook that uses hook_drush_help_alter to allow the 'magic' option.
  47. // We need to run 'drush cc drush' to clear the commandfile cache; otherwise, our include will not be found.
  48. $include_path = dirname(__FILE__) . '/hooks/magic_help_alter';
  49. $this->drush('version', array(), array('include' => $include_path, 'pipe' => NULL, 'magic' => '1234', 'strict' => NULL));
  50. }
  51. /**
  52. * Assert that errors are thrown for commands with missing callbacks.
  53. */
  54. public function testMissingCommandCallback() {
  55. $options = array(
  56. 'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  57. //'show-invoke' => TRUE,
  58. );
  59. $this->drush('missing-callback', array(), $options, NULL, NULL, self::EXIT_ERROR);
  60. }
  61. /**
  62. * Assert that commands depending on unknown commandfiles are detected.
  63. */
  64. public function testMissingDrushDependency() {
  65. $options = array(
  66. 'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
  67. 'backend' => NULL, // To obtain and parse the error log.
  68. );
  69. $this->drush('unit-drush-dependency', array(), $options, NULL, NULL, self::EXIT_ERROR);
  70. $parsed = $this->parse_backend_output($this->getOutput());
  71. $this->assertArrayHasKey("DRUSH_COMMANDFILE_DEPENDENCY_ERROR", $parsed['error_log']);
  72. }
  73. /**
  74. * Assert that commands in disabled modules are detected.
  75. */
  76. public function testDisabledModule() {
  77. $sites = $this->setUpDrupal(1, TRUE);
  78. $uri = key($sites);
  79. $root = $this->webroot();
  80. $options = array(
  81. 'root' => $root,
  82. 'uri' => $uri,
  83. 'cache' => NULL,
  84. );
  85. $this->drush('pm-download', array('devel'), $options);
  86. $options += array(
  87. 'backend' => NULL, // To obtain and parse the error log.
  88. );
  89. $this->drush('devel-download', array(), $options, NULL, NULL, self::EXIT_ERROR);
  90. $parsed = $this->parse_backend_output($this->getOutput());
  91. $this->assertArrayHasKey("DRUSH_COMMAND_DEPENDENCY_ERROR", $parsed['error_log']);
  92. }
  93. }