1 | <?php |
||
7 | class Arguments |
||
8 | { |
||
9 | use ArgumentAccessors; |
||
10 | |||
11 | const APPLICATION_OPTIONS = []; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $testFile; |
||
15 | protected $phpUnitOptions = []; |
||
16 | protected $applicationOptions = []; |
||
17 | |||
18 | /** |
||
19 | * Parses the given arguments string and instantiates a new object containing the arguments. |
||
20 | * |
||
21 | * @param string $argumentsInput |
||
22 | * @return $this |
||
23 | */ |
||
24 | public static function fromString($argumentsInput) |
||
28 | |||
29 | /** |
||
30 | * Adds an argument if it does not yet exist, otherwise the argument value is replaced. |
||
31 | * |
||
32 | * In case $value is left empty, the argument will be treated as a boolean option. If the |
||
33 | * name and value are not separated by a space, pass the correct separator as a third |
||
34 | * parameter. |
||
35 | * |
||
36 | * Unless an option is registered (in this class) as an application option, we will assume |
||
37 | * the option is meant to be passed through to PHPUnit. |
||
38 | * |
||
39 | * @param string $name |
||
40 | * @param mixed $value |
||
41 | * @param string $separator |
||
42 | */ |
||
43 | public function addArgument($name, $value = null, $separator = '=') |
||
55 | |||
56 | /** |
||
57 | * Returns a string containing all PHPUnit options with corresponding values in the correct format. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function phpUnitArguments() |
||
76 | |||
77 | /** |
||
78 | * Returns an array representation containing application options, PHPUnit options and the test file. |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | public function toArray() |
||
90 | |||
91 | /** |
||
92 | * Parses a raw arguments string. |
||
93 | * |
||
94 | * The following types of arguments will be parsed: space separated arguments, key/value and boolean arguments, |
||
95 | * and test file name arguments. Space separated arguments are key/value arguments separated by a space. Boolean |
||
96 | * and key/value arguments are regular options that either take no parameters or take a =-separated parameter. |
||
97 | * Test file name arguments are file names (without option flags). |
||
98 | * |
||
99 | * @param $argumentsInput |
||
100 | * @return $this |
||
101 | */ |
||
102 | protected function parse($argumentsInput) |
||
137 | |||
138 | /** |
||
139 | * Parses an argument string of an option (either key/value or boolean) and adds it to the list of arguments. |
||
140 | * |
||
141 | * @param string $argument |
||
142 | */ |
||
143 | protected function parseOption($argument) |
||
155 | |||
156 | /** |
||
157 | * Converts an argument string into the name of the option. |
||
158 | * |
||
159 | * @param string $argument |
||
160 | * @return mixed |
||
161 | */ |
||
162 | protected function optionName($argument) |
||
181 | |||
182 | /** |
||
183 | * Determines if the given argument string is an option. |
||
184 | * |
||
185 | * @param string $argument |
||
186 | * @return bool |
||
187 | */ |
||
188 | protected function isOption($argument) |
||
192 | |||
193 | /** |
||
194 | * Determines if the given option name is an application option. |
||
195 | * |
||
196 | * @param string $option |
||
197 | * @return bool |
||
198 | */ |
||
199 | protected function isApplicationOption($option) |
||
203 | |||
204 | /** |
||
205 | * Determines if the given option name belongs to an option that takes a space separated argument. |
||
206 | * |
||
207 | * @param string $option |
||
208 | * @return bool |
||
209 | */ |
||
210 | protected function isOptionWithSpaceSeparatedArgument($option) |
||
214 | } |
||
215 |