generated from opencodeco/ctl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hfctl_test
executable file
·92 lines (76 loc) · 2.67 KB
/
hfctl_test
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
HFCTL=$(dirname $(realpath $0))/hfctl
HFDIR=test-project
HFCID=runtime/hfctl.cid
function set_up_before_script() {
if [ -d $HFDIR ]; then
rm -rf $HFDIR
fi
$HFCTL create $HFDIR &> /dev/null
}
function tear_down_after_script() {
rm -rf $HFDIR
}
function test_should_display_help_information() {
assert_contains "Shows this help message" "$($HFCTL)"
assert_contains "Shows this help message" "$($HFCTL help)"
}
function test_should_test_project_been_created() {
assert_file_exists $HFDIR/vendor/autoload.php
}
function test_should_pre_check_fail_if_not_in_project_directory() {
assert_contains "Are you in a Hyperf project?" "$($HFCTL pre-check)"
assert_exit_code 1 "$($HFCTL pre-check)"
}
function test_should_pre_check_pass_if_in_project_directory() {
cd $HFDIR
assert_empty "$($HFCTL pre-check)"
}
function test_should_pre_check_fail_if_there_is_no_cid() {
cd $HFDIR
assert_contains "Hyperf server is not running" "$($HFCTL pre-check cid)"
}
function test_should_composer_commands_be_available() {
cd $HFDIR
assert_contains "Display help for a command" "$($HFCTL composer help)"
}
function test_should_start_show_logs_and_stop() {
cd $HFDIR
assert_contains "Hyperf server started at 9501" "$($HFCTL start)"
sleep 2
assert_file_exists $HFCID
assert_contains "[INFO] HTTP Server listening at 0.0.0.0:9501" "$($HFCTL logs)"
assert_equals "{\"method\":\"GET\",\"message\":\"Hello Hyperf.\"}" "$(curl -s http://localhost:9501)"
assert_equals "$(cat $HFCID)" "$($HFCTL stop)"
assert_file_not_exists $HFCID
}
function test_should_install_watcher_and_watch_for_changes() {
cd $HFDIR
assert_contains "Hyperf server started at 9501" "$($HFCTL watch 2> /dev/null)"
sleep 2
assert_file_exists $HFCID
assert_contains "Hot reload watcher for Hyperf" "$($HFCTL composer show hyperf/watcher)"
assert_equals "{\"method\":\"GET\",\"message\":\"Hello Hyperf.\"}" "$(curl -s http://localhost:9501)"
assert_equals "$(cat $HFCID)" "$($HFCTL stop)"
assert_file_not_exists $HFCID
}
function test_should_run_hyperf_console_commands() {
cd $HFDIR
assert_contains "Console Tool" "$($HFCTL console)"
}
function test_should_run_test_command() {
cd $HFDIR
assert_contains "OK (1 test, 2 assertions)" "$($HFCTL test)"
}
function test_should_run_lint_command() {
cd $HFDIR
assert_contains "Fixed 8 of 27 files" "$($HFCTL lint 2> /dev/null)"
}
function test_should_run_analyse_command() {
cd $HFDIR
assert_contains "No errors" "$($HFCTL analyse 2> /dev/null)"
}
if [[ $0 == "./hfctl_test" ]]; then
export HFTTY="-lno-tty"
./bashunit ./hfctl_test $@
fi