-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.php
More file actions
119 lines (99 loc) · 2.17 KB
/
cli.php
File metadata and controls
119 lines (99 loc) · 2.17 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// composer includes
require __DIR__ . '/vendor/autoload.php';
//print_r($argv);
//print_r($argc);
/*
* argv[0] -> cli.php
* argv[1] -> root
* argv[2] -> suite (optional)
* argv[3] -> case (optional)
* argv[4] -> -report=html (optional)
* argv[5] -> -output="./output/out.html" (optional), if no path is specified it will be saved in the root
* */
$output = '.'. DIRECTORY_SEPARATOR;
$report = 'html';
$output_index = 0;
$report_index = 0;
$test_start_time = 0;
$test_end_time = 0;
$test_time = 0;
foreach ($argv as $i => $arg)
{
$search = substr($arg, 0, 7);
if ($search == '-report')
{
$type_out = explode("=", $arg);
$report = end($type_out);
$argc--;
$report_index = $i;
}
if ($search == '-output')
{
$search_path = explode("=", $arg);
$output = end($search_path);
$argc--;
$output_index = $i;
}
}
// remove output and report parameters, so the rest are in the same order for the execution (suite, class, function)
if ($output_index > 0) unset($argv[$output_index]);
if ($report_index > 0) unset($argv[$report_index]);
$argv = array_values($argv);
if ($argc < 2)
{
echo 'Missing test_root and test_suite'. PHP_EOL;
exit;
}
$run = new \CaboLabs\Debbie\DebbieRun();
$test_start_time = microtime(true);
$run->init($argv[1]);
// Method specific
if ($argc > 4)
{
$methods = [];
for ($i = 4; $i < $argc; $i++) {
$methods[] = $argv[$i];
}
$run->run_case($argv[2], $argv[3], $methods);
}
// case or cases specific
else if ($argc == 4)
{
$run->run_cases($argv[2], $argv[3]);
}
// suite specified
else if ($argc == 3)
{
$run->run_suite($argv[2]);
}
// run all
else
{
$run->run_all();
}
if (!in_array($report, ['html', 'text', 'junit']))
{
echo '"-report=" should be equal to "html", "text" or "junit"'. PHP_EOL;
exit(1);
}
$exit_code = 0;
if ($report == 'html')
{
$exit_code = $run->render_reports_html($output);
}
else if ($report == 'text')
{
$exit_code = $run->render_reports();
}
else if ($report == 'junit')
{
$exit_code = $run->generate_junit_xml();
}
else
{
$exit_code = $run->render_reports_html($output);
}
echo "Exit code: $exit_code". PHP_EOL;
exit($exit_code);
?>