unit.drush.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // $Id$
  3. /*
  4. * @file
  5. * Commands which are useful for unit tests.
  6. */
  7. /**
  8. * Implementation of hook_drush_command().
  9. */
  10. function unit_drush_command() {
  11. $items['unit-eval'] = array(
  12. 'description' => 'Works like php-eval. Used for testing $command_specific context.',
  13. 'bootstrap' => DRUSH_BOOTSTRAP_MAX,
  14. 'callback' => 'drush_core_php_eval', // Note - no invoke hooks.
  15. );
  16. $items['unit-invoke'] = array(
  17. 'description' => 'Return an array indicating which invoke hooks got called.',
  18. 'bootstrap' => DRUSH_BOOTSTRAP_NONE,
  19. );
  20. return $items;
  21. }
  22. /*
  23. * Dynamically append custom bash code to the generated .bashrc.
  24. *
  25. * @see coreCase::testCoreCLI().
  26. */
  27. function unit_cli_bashrc($drush_command, $interactive_mode) {
  28. return drush_get_option('unit-extra');
  29. }
  30. // Implement each invoke hook with the same single line of code.
  31. // That line records that the hook was called.
  32. function drush_unit_invoke_init() {unit_invoke_log(__FUNCTION__);}
  33. function drush_unit_invoke_validate() {unit_invoke_log(__FUNCTION__);}
  34. function drush_unit_pre_unit_invoke() {unit_invoke_log(__FUNCTION__);}
  35. function drush_unit_invoke() {unit_invoke_log(__FUNCTION__);}
  36. function drush_unit_pre_unit_invoke_rollback() {unit_invoke_log(__FUNCTION__);}
  37. function drush_unit_post_unit_invoke_rollback() {unit_invoke_log(__FUNCTION__);}
  38. // Record that hook_drush_init() fired.
  39. function unit_drush_init() {
  40. $command = drush_get_command();
  41. if ($command['command'] == 'unit-invoke') {
  42. unit_invoke_log(__FUNCTION__);
  43. }
  44. }
  45. function drush_unit_post_unit_invoke() {
  46. // Record that this hook was called.
  47. unit_invoke_log(__FUNCTION__);
  48. // Make sure we enter into rollback.
  49. drush_set_error('');
  50. }
  51. /*
  52. * The final invoke hook. Emit the call history.
  53. * Cannot use 'exit' as it does not fire in rollback scenario.
  54. */
  55. function drush_unit_invoke_validate_rollback() {
  56. unit_invoke_log(__FUNCTION__);
  57. print json_encode(unit_invoke_log());
  58. }
  59. function unit_invoke_log($function = NULL) {
  60. static $called = array();
  61. if ($function) {
  62. $called[] = $function;
  63. }
  64. else {
  65. return $called;
  66. }
  67. }