/
naith.php
173 lines (139 loc) · 4.27 KB
/
naith.php
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*
* We want to be strict and handle all errors.
*/
error_reporting(E_ALL | E_STRICT);
require_once (dirname(__FILE__) . '/NaithCliRunner.class.php');
require_once (dirname(__FILE__) . '/NaithCliReport.class.php');
require_once (dirname(__FILE__) . '/NaithJunitReport.class.php');
/*
* Argument handling!
*/
$arguments = array_slice($argv, 1);
$next_value_key = null;
$options = array();
$action_name = null;
foreach ($arguments as $argument)
{
if (substr($argument, 0, 2) == '--')
{
$next_value_key = substr($argument, 2);
}
else
{
if ($next_value_key !== null)
{
if (!array_key_exists($next_value_key, $options))
{
$options[$next_value_key] = array();
}
if (substr($argument, 0, 1) == '"' && substr($argument, -1, 1) == '"')
{
/*
* It's something like "example" (with quotes)
*/
$argument = substr($argument, 1, strlen($argument) - 2);
}
$options[$next_value_key][] = $argument;
$next_value_key = null;
}
else
{
if ($action_name !== null)
{
throw new Exception('Unknown option ' . $argument);
}
$action_name = $argument;
}
}
}
/*
* Execute the Command with the given options!
*/
if (in_array($action_name, array("make-coverage-overview", "make-untested-code-overview")))
{
$excluded_paths = array();
if (isset($options['excluded_path']))
{
$excluded_paths = $options['excluded_path'];
}
$minimum_code_coverage = 0;
if (isset($options['minimum_code_coverage']))
{
list($minimum_code_coverage) = $options['minimum_code_coverage'];
}
$base_directory = dirname(getcwd());
if (isset($options['base_directory']))
{
list($base_directory) = $options['base_directory'];
}
list($coverage_file_path) = $options['coverage_file_path'];
$report = new NaithCliReport( array(
'base_directory' => $base_directory,
'excluded_paths' => $excluded_paths,
'coverage_file_path' => $coverage_file_path,
'minimum_code_coverage' => $minimum_code_coverage,
));
}
switch ($action_name)
{
case "run-test":
if (isset($options['coverage_file_path']))
{
NaithCliRunner::setCoverageFilePath($options['coverage_file_path'][0]);
}
if (isset($options['tests_report_path']))
{
NaithCliRunner::setTestsReportPath($options['tests_report_path'][0], $options['test_file'][0]);
}
NaithCliRunner::bootstrapForTest();
if (isset($options['prepend_file']))
{
foreach ($options['prepend_file'] as $prepended_file)
{
require ($prepended_file);
}
}
if (isset($options['test_file']))
{
foreach ($options['test_file'] as $test_file)
{
require ($test_file);
}
}
break;
case "make-coverage-overview":
$report->makeCoverageOverview();
break;
case "make-untested-code-overview":
$report->makeUntestedCodeOverview();
break;
case "generate-junit-xml":
$junit_xml_path = null;
if (isset($options['junit_xml_path']))
{
list($junit_xml_path) = $options['junit_xml_path'];
}
$excluded_paths = array();
if (isset($options['excluded_path']))
{
$excluded_paths = $options['excluded_path'];
}
$base_directory = dirname(getcwd());
if (isset($options['base_directory']))
{
list($base_directory) = $options['base_directory'];
}
$tests_report_path = null;
if (isset($options['tests_report_path']))
{
list($tests_report_path) = $options['tests_report_path'];
}
$report = new NaithJunitReport( array(
'base_directory' => $base_directory,
'excluded_paths' => $excluded_paths,
'tests_report_path' => $tests_report_path
));
$report->writeJunitXmlToFile($junit_xml_path);
break;
}