1 | <?php |
||
7 | class Arguments |
||
8 | { |
||
9 | use ArgumentAccessors; |
||
10 | |||
11 | const APPLICATION_OPTIONS = [ |
||
12 | 'disable-on-start', |
||
13 | ]; |
||
14 | |||
15 | protected $testFile; |
||
16 | protected $phpUnitOptions = []; |
||
17 | protected $applicationOptions = []; |
||
18 | |||
19 | /** |
||
20 | * Parses the given arguments string and instantiates a new object containing the arguments. |
||
21 | * |
||
22 | * @param string $argumentsInput |
||
23 | * @return $this |
||
24 | */ |
||
25 | public static function fromString($argumentsInput) |
||
29 | |||
30 | /** |
||
31 | * Adds an argument if it does not yet exist, otherwise the argument value is replaced. |
||
32 | * |
||
33 | * In case $value is left empty, the argument will be treated as a boolean option. If the |
||
34 | * name and value are not separated by a space, pass the correct separator as a third |
||
35 | * parameter. |
||
36 | * |
||
37 | * Unless an option is registered (in this class) as an application option, we will assume |
||
38 | * the option is meant to be passed through to PHPUnit. |
||
39 | * |
||
40 | * @param string $name |
||
41 | * @param mixed $value |
||
42 | * @param string $separator |
||
43 | */ |
||
44 | public function addArgument($name, $value = null, $separator = '=') |
||
56 | |||
57 | /** |
||
58 | * Returns a string containing all PHPUnit options with corresponding values in the correct format. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function phpUnitArguments() |
||
80 | |||
81 | /** |
||
82 | * Returns an array representation containing application options, PHPUnit options and the test file. |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | public function toArray() |
||
94 | |||
95 | /** |
||
96 | * Parses a raw arguments string. |
||
97 | * |
||
98 | * The following types of arguments will be parsed: space separated arguments, key/value and boolean arguments, |
||
99 | * and test file name arguments. Space separated arguments are key/value arguments separated by a space. Boolean |
||
100 | * and key/value arguments are regular options that either take no parameters or take a =-separated parameter. |
||
101 | * Test file name arguments are file names (without option flags). |
||
102 | * |
||
103 | * @param $argumentsInput |
||
104 | * @return $this |
||
105 | */ |
||
106 | protected function parse($argumentsInput) |
||
141 | |||
142 | /** |
||
143 | * Parses an argument string of an option (either key/value or boolean) and adds it to the list of arguments. |
||
144 | * |
||
145 | * @param string $argument |
||
146 | */ |
||
147 | protected function parseOption($argument) |
||
159 | |||
160 | /** |
||
161 | * Converts an argument string into the name of the option. |
||
162 | * |
||
163 | * @param string $argument |
||
164 | * @return mixed |
||
165 | */ |
||
166 | protected function optionName($argument) |
||
185 | |||
186 | /** |
||
187 | * Determines if the given argument string is an option. |
||
188 | * |
||
189 | * @param string $argument |
||
190 | * @return bool |
||
191 | */ |
||
192 | protected function isOption($argument) |
||
196 | |||
197 | /** |
||
198 | * Determines if the given option name is an application option. |
||
199 | * |
||
200 | * @param string $option |
||
201 | * @return bool |
||
202 | */ |
||
203 | protected function isApplicationOption($option) |
||
207 | |||
208 | /** |
||
209 | * Determines if the given option name belongs to an option that takes a space separated argument. |
||
210 | * |
||
211 | * @param string $option |
||
212 | * @return bool |
||
213 | */ |
||
214 | protected function isOptionWithSpaceSeparatedArgument($option) |
||
218 | } |
||
219 |