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