27
27
final class Help
28
28
{
29
29
private const LEFT_MARGIN = ' ' ;
30
- private const HELP_TEXT = [
31
- 'Usage ' => [
32
- ['text ' => 'phpunit [options] UnitTest [UnitTest.php] ' ],
33
- ['text ' => 'phpunit [options] <directory> ' ],
34
- ],
35
- 'Code Coverage Options ' => [
36
- ['arg ' => '--coverage-clover <file> ' , 'desc ' => 'Generate code coverage report in Clover XML format ' ],
37
- ['arg ' => '--coverage-crap4j <file> ' , 'desc ' => 'Generate code coverage report in Crap4J XML format ' ],
38
- ['arg ' => '--coverage-html <dir> ' , 'desc ' => 'Generate code coverage report in HTML format ' ],
39
- ['arg ' => '--coverage-php <file> ' , 'desc ' => 'Export PHP_CodeCoverage object to file ' ],
40
- ['arg ' => '--coverage-text=<file> ' , 'desc ' => 'Generate code coverage report in text format [default: standard output] ' ],
41
- ['arg ' => '--coverage-xml <dir> ' , 'desc ' => 'Generate code coverage report in PHPUnit XML format ' ],
42
- ['arg ' => '--whitelist <dir> ' , 'desc ' => 'Whitelist <dir> for code coverage analysis ' ],
43
- ['arg ' => '--disable-coverage-ignore ' , 'desc ' => 'Disable annotations for ignoring code coverage ' ],
44
- ['arg ' => '--no-coverage ' , 'desc ' => 'Ignore code coverage configuration ' ],
45
- ['arg ' => '--dump-xdebug-filter <file> ' , 'desc ' => 'Generate script to set Xdebug code coverage filter ' ],
46
- ],
47
-
48
- 'Logging Options ' => [
49
- ['arg ' => '--log-junit <file> ' , 'desc ' => 'Log test execution in JUnit XML format to file ' ],
50
- ['arg ' => '--log-teamcity <file> ' , 'desc ' => 'Log test execution in TeamCity format to file ' ],
51
- ['arg ' => '--testdox-html <file> ' , 'desc ' => 'Write agile documentation in HTML format to file ' ],
52
- ['arg ' => '--testdox-text <file> ' , 'desc ' => 'Write agile documentation in Text format to file ' ],
53
- ['arg ' => '--testdox-xml <file> ' , 'desc ' => 'Write agile documentation in XML format to file ' ],
54
- ['arg ' => '--reverse-list ' , 'desc ' => 'Print defects in reverse order ' ],
55
- ['arg ' => '--no-logging ' , 'desc ' => 'Ignore logging configuration ' ],
56
- ],
57
-
58
- 'Test Selection Options ' => [
59
- ['arg ' => '--filter <pattern> ' , 'desc ' => 'Filter which tests to run ' ],
60
- ['arg ' => '--testsuite <name> ' , 'desc ' => 'Filter which testsuite to run ' ],
61
- ['arg ' => '--group <name> ' , 'desc ' => 'Only runs tests from the specified group(s) ' ],
62
- ['arg ' => '--exclude-group <name> ' , 'desc ' => 'Exclude tests from the specified group(s) ' ],
63
- ['arg ' => '--list-groups ' , 'desc ' => 'List available test groups ' ],
64
- ['arg ' => '--list-suites ' , 'desc ' => 'List available test suites ' ],
65
- ['arg ' => '--list-tests ' , 'desc ' => 'List available tests ' ],
66
- ['arg ' => '--list-tests-xml <file> ' , 'desc ' => 'List available tests in XML format ' ],
67
- ['arg ' => '--test-suffix <suffixes> ' , 'desc ' => 'Only search for test in files with specified suffix(es). Default: Test.php,.phpt ' ],
68
- ],
69
-
70
- 'Test Execution Options ' => [
71
- ['arg ' => '--dont-report-useless-tests ' , 'desc ' => 'Do not report tests that do not test anything ' ],
72
- ['arg ' => '--strict-coverage ' , 'desc ' => 'Be strict about @covers annotation usage ' ],
73
- ['arg ' => '--strict-global-state ' , 'desc ' => 'Be strict about changes to global state ' ],
74
- ['arg ' => '--disallow-test-output ' , 'desc ' => 'Be strict about output during tests ' ],
75
- ['arg ' => '--disallow-resource-usage ' , 'desc ' => 'Be strict about resource usage during small tests ' ],
76
- ['arg ' => '--enforce-time-limit ' , 'desc ' => 'Enforce time limit based on test size ' ],
77
- ['arg ' => '--default-time-limit=<sec> ' , 'desc ' => 'Timeout in seconds for tests without @small, @medium or @large ' ],
78
- ['arg ' => '--disallow-todo-tests ' , 'desc ' => 'Disallow @todo-annotated tests ' ],
79
- ['spacer ' => '' ],
80
-
81
- ['arg ' => '--process-isolation ' , 'desc ' => 'Run each test in a separate PHP process ' ],
82
- ['arg ' => '--globals-backup ' , 'desc ' => 'Backup and restore $GLOBALS for each test ' ],
83
- ['arg ' => '--static-backup ' , 'desc ' => 'Backup and restore static attributes for each test ' ],
84
- ['spacer ' => '' ],
85
-
86
- ['arg ' => '--colors=<flag> ' , 'desc ' => 'Use colors in output ("never", "auto" or "always") ' ],
87
- ['arg ' => '--columns <n> ' , 'desc ' => 'Number of columns to use for progress output ' ],
88
- ['arg ' => '--columns max ' , 'desc ' => 'Use maximum number of columns for progress output ' ],
89
- ['arg ' => '--stderr ' , 'desc ' => 'Write to STDERR instead of STDOUT ' ],
90
- ['arg ' => '--stop-on-defect ' , 'desc ' => 'Stop execution upon first not-passed test ' ],
91
- ['arg ' => '--stop-on-error ' , 'desc ' => 'Stop execution upon first error ' ],
92
- ['arg ' => '--stop-on-failure ' , 'desc ' => 'Stop execution upon first error or failure ' ],
93
- ['arg ' => '--stop-on-warning ' , 'desc ' => 'Stop execution upon first warning ' ],
94
- ['arg ' => '--stop-on-risky ' , 'desc ' => 'Stop execution upon first risky test ' ],
95
- ['arg ' => '--stop-on-skipped ' , 'desc ' => 'Stop execution upon first skipped test ' ],
96
- ['arg ' => '--stop-on-incomplete ' , 'desc ' => 'Stop execution upon first incomplete test ' ],
97
- ['arg ' => '--fail-on-warning ' , 'desc ' => 'Treat tests with warnings as failures ' ],
98
- ['arg ' => '--fail-on-risky ' , 'desc ' => 'Treat risky tests as failures ' ],
99
- ['arg ' => '-v|--verbose ' , 'desc ' => 'Output more verbose information ' ],
100
- ['arg ' => '--debug ' , 'desc ' => 'Display debugging information ' ],
101
- ['spacer ' => '' ],
102
-
103
- ['arg ' => '--loader <loader> ' , 'desc ' => 'TestSuiteLoader implementation to use ' ],
104
- ['arg ' => '--repeat <times> ' , 'desc ' => 'Runs the test(s) repeatedly ' ],
105
- ['arg ' => '--teamcity ' , 'desc ' => 'Report test execution progress in TeamCity format ' ],
106
- ['arg ' => '--testdox ' , 'desc ' => 'Report test execution progress in TestDox format ' ],
107
- ['arg ' => '--testdox-group ' , 'desc ' => 'Only include tests from the specified group(s) ' ],
108
- ['arg ' => '--testdox-exclude-group ' , 'desc ' => 'Exclude tests from the specified group(s) ' ],
109
- ['arg ' => '--no-interaction ' , 'desc ' => 'Disable TestDox progress animation ' ],
110
- ['arg ' => '--printer <printer> ' , 'desc ' => 'TestListener implementation to use ' ],
111
- ['spacer ' => '' ],
112
-
113
- ['arg ' => '--order-by=<order> ' , 'desc ' => 'Run tests in order: default|defects|duration|no-depends|random|reverse|size ' ],
114
- ['arg ' => '--random-order-seed=<N> ' , 'desc ' => 'Use a specific random seed <N> for random order ' ],
115
- ['arg ' => '--cache-result ' , 'desc ' => 'Write test results to cache file ' ],
116
- ['arg ' => '--do-not-cache-result ' , 'desc ' => 'Do not write test results to cache file ' ],
117
- ],
118
-
119
- 'Configuration Options ' => [
120
- ['arg ' => '--prepend <file> ' , 'desc ' => 'A PHP script that is included as early as possible ' ],
121
- ['arg ' => '--bootstrap <file> ' , 'desc ' => 'A PHP script that is included before the tests run ' ],
122
- ['arg ' => '-c|--configuration <file> ' , 'desc ' => 'Read configuration from XML file ' ],
123
- ['arg ' => '--no-configuration ' , 'desc ' => 'Ignore default configuration file (phpunit.xml) ' ],
124
- ['arg ' => '--no-extensions ' , 'desc ' => 'Do not load PHPUnit extensions ' ],
125
- ['arg ' => '--include-path <path(s)> ' , 'desc ' => 'Prepend PHP \'s include_path with given path(s) ' ],
126
- ['arg ' => '-d <key[=value]> ' , 'desc ' => 'Sets a php.ini value ' ],
127
- ['arg ' => '--generate-configuration ' , 'desc ' => 'Generate configuration file with suggested settings ' ],
128
- ['arg ' => '--cache-result-file=<file> ' , 'desc ' => 'Specify result cache path and filename ' ],
129
- ],
130
-
131
- 'Miscellaneous Options ' => [
132
- ['arg ' => '-h|--help ' , 'desc ' => 'Prints this usage information ' ],
133
- ['arg ' => '--version ' , 'desc ' => 'Prints the version and exits ' ],
134
- ['arg ' => '--atleast-version <min> ' , 'desc ' => 'Checks that version is greater than min and exits ' ],
135
- ['arg ' => '--check-version ' , 'desc ' => 'Check whether PHPUnit is the latest version ' ],
136
- ],
137
-
138
- ];
139
30
140
31
/**
141
32
* @var int Number of columns required to write the longest option name to the console
@@ -164,7 +55,7 @@ public function __construct(?int $width = null, ?bool $withColor = null)
164
55
$ this ->hasColor = $ withColor ;
165
56
}
166
57
167
- foreach (self :: HELP_TEXT as $ options ) {
58
+ foreach ($ this -> elements () as $ options ) {
168
59
foreach ($ options as $ option ) {
169
60
if (isset ($ option ['arg ' ])) {
170
61
$ this ->maxArgLength = max ($ this ->maxArgLength , isset ($ option ['arg ' ]) ? strlen ($ option ['arg ' ]) : 0 );
@@ -189,7 +80,7 @@ public function writeToConsole(): void
189
80
190
81
private function writePlaintext (): void
191
82
{
192
- foreach (self :: HELP_TEXT as $ section => $ options ) {
83
+ foreach ($ this -> elements () as $ section => $ options ) {
193
84
print "{$ section }: " . PHP_EOL ;
194
85
195
86
if ($ section !== 'Usage ' ) {
@@ -217,7 +108,7 @@ private function writePlaintext(): void
217
108
218
109
private function writeWithColor (): void
219
110
{
220
- foreach (self :: HELP_TEXT as $ section => $ options ) {
111
+ foreach ($ this -> elements () as $ section => $ options ) {
221
112
print Color::colorize ('fg-yellow ' , "{$ section }: " ) . PHP_EOL ;
222
113
223
114
foreach ($ options as $ option ) {
@@ -252,4 +143,120 @@ static function ($matches)
252
143
print PHP_EOL ;
253
144
}
254
145
}
146
+
147
+ /**
148
+ * @psalm-return array<non-empty-string, non-empty-list<array{text: non-empty-string}|array{arg: non-empty-string, desc: non-empty-string}|array{spacer: ''}>>
149
+ */
150
+ private function elements (): array
151
+ {
152
+ return [
153
+ 'Usage ' => [
154
+ ['text ' => 'phpunit [options] UnitTest [UnitTest.php] ' ],
155
+ ['text ' => 'phpunit [options] <directory> ' ],
156
+ ],
157
+
158
+ 'Code Coverage Options ' => [
159
+ ['arg ' => '--coverage-clover <file> ' , 'desc ' => 'Generate code coverage report in Clover XML format ' ],
160
+ ['arg ' => '--coverage-crap4j <file> ' , 'desc ' => 'Generate code coverage report in Crap4J XML format ' ],
161
+ ['arg ' => '--coverage-html <dir> ' , 'desc ' => 'Generate code coverage report in HTML format ' ],
162
+ ['arg ' => '--coverage-php <file> ' , 'desc ' => 'Export PHP_CodeCoverage object to file ' ],
163
+ ['arg ' => '--coverage-text=<file> ' , 'desc ' => 'Generate code coverage report in text format [default: standard output] ' ],
164
+ ['arg ' => '--coverage-xml <dir> ' , 'desc ' => 'Generate code coverage report in PHPUnit XML format ' ],
165
+ ['arg ' => '--whitelist <dir> ' , 'desc ' => 'Whitelist <dir> for code coverage analysis ' ],
166
+ ['arg ' => '--disable-coverage-ignore ' , 'desc ' => 'Disable annotations for ignoring code coverage ' ],
167
+ ['arg ' => '--no-coverage ' , 'desc ' => 'Ignore code coverage configuration ' ],
168
+ ['arg ' => '--dump-xdebug-filter <file> ' , 'desc ' => 'Generate script to set Xdebug code coverage filter ' ],
169
+ ],
170
+
171
+ 'Logging Options ' => [
172
+ ['arg ' => '--log-junit <file> ' , 'desc ' => 'Log test execution in JUnit XML format to file ' ],
173
+ ['arg ' => '--log-teamcity <file> ' , 'desc ' => 'Log test execution in TeamCity format to file ' ],
174
+ ['arg ' => '--testdox-html <file> ' , 'desc ' => 'Write agile documentation in HTML format to file ' ],
175
+ ['arg ' => '--testdox-text <file> ' , 'desc ' => 'Write agile documentation in Text format to file ' ],
176
+ ['arg ' => '--testdox-xml <file> ' , 'desc ' => 'Write agile documentation in XML format to file ' ],
177
+ ['arg ' => '--reverse-list ' , 'desc ' => 'Print defects in reverse order ' ],
178
+ ['arg ' => '--no-logging ' , 'desc ' => 'Ignore logging configuration ' ],
179
+ ],
180
+
181
+ 'Test Selection Options ' => [
182
+ ['arg ' => '--filter <pattern> ' , 'desc ' => 'Filter which tests to run ' ],
183
+ ['arg ' => '--testsuite <name> ' , 'desc ' => 'Filter which testsuite to run ' ],
184
+ ['arg ' => '--group <name> ' , 'desc ' => 'Only runs tests from the specified group(s) ' ],
185
+ ['arg ' => '--exclude-group <name> ' , 'desc ' => 'Exclude tests from the specified group(s) ' ],
186
+ ['arg ' => '--list-groups ' , 'desc ' => 'List available test groups ' ],
187
+ ['arg ' => '--list-suites ' , 'desc ' => 'List available test suites ' ],
188
+ ['arg ' => '--list-tests ' , 'desc ' => 'List available tests ' ],
189
+ ['arg ' => '--list-tests-xml <file> ' , 'desc ' => 'List available tests in XML format ' ],
190
+ ['arg ' => '--test-suffix <suffixes> ' , 'desc ' => 'Only search for test in files with specified suffix(es). Default: Test.php,.phpt ' ],
191
+ ],
192
+
193
+ 'Test Execution Options ' => [
194
+ ['arg ' => '--dont-report-useless-tests ' , 'desc ' => 'Do not report tests that do not test anything ' ],
195
+ ['arg ' => '--strict-coverage ' , 'desc ' => 'Be strict about @covers annotation usage ' ],
196
+ ['arg ' => '--strict-global-state ' , 'desc ' => 'Be strict about changes to global state ' ],
197
+ ['arg ' => '--disallow-test-output ' , 'desc ' => 'Be strict about output during tests ' ],
198
+ ['arg ' => '--disallow-resource-usage ' , 'desc ' => 'Be strict about resource usage during small tests ' ],
199
+ ['arg ' => '--enforce-time-limit ' , 'desc ' => 'Enforce time limit based on test size ' ],
200
+ ['arg ' => '--default-time-limit=<sec> ' , 'desc ' => 'Timeout in seconds for tests without @small, @medium or @large ' ],
201
+ ['arg ' => '--disallow-todo-tests ' , 'desc ' => 'Disallow @todo-annotated tests ' ],
202
+ ['spacer ' => '' ],
203
+
204
+ ['arg ' => '--process-isolation ' , 'desc ' => 'Run each test in a separate PHP process ' ],
205
+ ['arg ' => '--globals-backup ' , 'desc ' => 'Backup and restore $GLOBALS for each test ' ],
206
+ ['arg ' => '--static-backup ' , 'desc ' => 'Backup and restore static attributes for each test ' ],
207
+ ['spacer ' => '' ],
208
+
209
+ ['arg ' => '--colors=<flag> ' , 'desc ' => 'Use colors in output ("never", "auto" or "always") ' ],
210
+ ['arg ' => '--columns <n> ' , 'desc ' => 'Number of columns to use for progress output ' ],
211
+ ['arg ' => '--columns max ' , 'desc ' => 'Use maximum number of columns for progress output ' ],
212
+ ['arg ' => '--stderr ' , 'desc ' => 'Write to STDERR instead of STDOUT ' ],
213
+ ['arg ' => '--stop-on-defect ' , 'desc ' => 'Stop execution upon first not-passed test ' ],
214
+ ['arg ' => '--stop-on-error ' , 'desc ' => 'Stop execution upon first error ' ],
215
+ ['arg ' => '--stop-on-failure ' , 'desc ' => 'Stop execution upon first error or failure ' ],
216
+ ['arg ' => '--stop-on-warning ' , 'desc ' => 'Stop execution upon first warning ' ],
217
+ ['arg ' => '--stop-on-risky ' , 'desc ' => 'Stop execution upon first risky test ' ],
218
+ ['arg ' => '--stop-on-skipped ' , 'desc ' => 'Stop execution upon first skipped test ' ],
219
+ ['arg ' => '--stop-on-incomplete ' , 'desc ' => 'Stop execution upon first incomplete test ' ],
220
+ ['arg ' => '--fail-on-warning ' , 'desc ' => 'Treat tests with warnings as failures ' ],
221
+ ['arg ' => '--fail-on-risky ' , 'desc ' => 'Treat risky tests as failures ' ],
222
+ ['arg ' => '-v|--verbose ' , 'desc ' => 'Output more verbose information ' ],
223
+ ['arg ' => '--debug ' , 'desc ' => 'Display debugging information ' ],
224
+ ['spacer ' => '' ],
225
+
226
+ ['arg ' => '--loader <loader> ' , 'desc ' => 'TestSuiteLoader implementation to use ' ],
227
+ ['arg ' => '--repeat <times> ' , 'desc ' => 'Runs the test(s) repeatedly ' ],
228
+ ['arg ' => '--teamcity ' , 'desc ' => 'Report test execution progress in TeamCity format ' ],
229
+ ['arg ' => '--testdox ' , 'desc ' => 'Report test execution progress in TestDox format ' ],
230
+ ['arg ' => '--testdox-group ' , 'desc ' => 'Only include tests from the specified group(s) ' ],
231
+ ['arg ' => '--testdox-exclude-group ' , 'desc ' => 'Exclude tests from the specified group(s) ' ],
232
+ ['arg ' => '--no-interaction ' , 'desc ' => 'Disable TestDox progress animation ' ],
233
+ ['arg ' => '--printer <printer> ' , 'desc ' => 'TestListener implementation to use ' ],
234
+ ['spacer ' => '' ],
235
+
236
+ ['arg ' => '--order-by=<order> ' , 'desc ' => 'Run tests in order: default|defects|duration|no-depends|random|reverse|size ' ],
237
+ ['arg ' => '--random-order-seed=<N> ' , 'desc ' => 'Use a specific random seed <N> for random order ' ],
238
+ ['arg ' => '--cache-result ' , 'desc ' => 'Write test results to cache file ' ],
239
+ ['arg ' => '--do-not-cache-result ' , 'desc ' => 'Do not write test results to cache file ' ],
240
+ ],
241
+
242
+ 'Configuration Options ' => [
243
+ ['arg ' => '--prepend <file> ' , 'desc ' => 'A PHP script that is included as early as possible ' ],
244
+ ['arg ' => '--bootstrap <file> ' , 'desc ' => 'A PHP script that is included before the tests run ' ],
245
+ ['arg ' => '-c|--configuration <file> ' , 'desc ' => 'Read configuration from XML file ' ],
246
+ ['arg ' => '--no-configuration ' , 'desc ' => 'Ignore default configuration file (phpunit.xml) ' ],
247
+ ['arg ' => '--no-extensions ' , 'desc ' => 'Do not load PHPUnit extensions ' ],
248
+ ['arg ' => '--include-path <path(s)> ' , 'desc ' => 'Prepend PHP \'s include_path with given path(s) ' ],
249
+ ['arg ' => '-d <key[=value]> ' , 'desc ' => 'Sets a php.ini value ' ],
250
+ ['arg ' => '--generate-configuration ' , 'desc ' => 'Generate configuration file with suggested settings ' ],
251
+ ['arg ' => '--cache-result-file=<file> ' , 'desc ' => 'Specify result cache path and filename ' ],
252
+ ],
253
+
254
+ 'Miscellaneous Options ' => [
255
+ ['arg ' => '-h|--help ' , 'desc ' => 'Prints this usage information ' ],
256
+ ['arg ' => '--version ' , 'desc ' => 'Prints the version and exits ' ],
257
+ ['arg ' => '--atleast-version <min> ' , 'desc ' => 'Checks that version is greater than min and exits ' ],
258
+ ['arg ' => '--check-version ' , 'desc ' => 'Check whether PHPUnit is the latest version ' ],
259
+ ],
260
+ ];
261
+ }
255
262
}
0 commit comments