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