1 | <?php |
||
14 | class TestMethod extends ExecutableTest |
||
15 | { |
||
16 | /** |
||
17 | * The path to the test case file. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $path; |
||
22 | |||
23 | /** |
||
24 | * A set of filters for test, they are merged into phpunit's --filter option. |
||
25 | * |
||
26 | * @var string[] |
||
27 | */ |
||
28 | protected $filters; |
||
29 | |||
30 | /** |
||
31 | * Constructor. |
||
32 | * |
||
33 | * Passed filters must be unescaped and must represent test name, optionally including |
||
34 | * dataset name (numeric or named). |
||
35 | * |
||
36 | * @param string $testPath path to phpunit test case file |
||
37 | * @param string|string[] $filters array of filters or single filter |
||
38 | */ |
||
39 | 21 | public function __construct($testPath, $filters) |
|
46 | |||
47 | /** |
||
48 | * Returns the test method's filters. |
||
49 | * |
||
50 | * @return string[] |
||
51 | */ |
||
52 | public function getFilters() |
||
53 | { |
||
54 | return $this->filters; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Returns the test method's name. |
||
59 | * |
||
60 | * This method will join all filters via pipe character and return as string. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 3 | public function getName() |
|
68 | |||
69 | /** |
||
70 | * Additional processing for options being passed to PHPUnit. |
||
71 | * |
||
72 | * This sets up the --filter switch used to run a single PHPUnit test method. |
||
73 | * This method also provide escaping for method name to be used as filter regexp. |
||
74 | * |
||
75 | * @param array $options |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | protected function prepareOptions($options) |
||
80 | { |
||
81 | $re = array_reduce($this->filters, function ($r, $v) { |
||
82 | $isDataSet = strpos($v, ' with data set ') !== false; |
||
83 | |||
84 | return ($r ? $r . '|' : '') . preg_quote($v, '/') . ($isDataSet ? '$' : "(?:\s|\$)"); |
||
85 | }); |
||
86 | $options['filter'] = '/' . $re . '/'; |
||
87 | |||
88 | return $options; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get the expected count of tests to be executed. |
||
93 | * |
||
94 | * @return int |
||
95 | */ |
||
96 | 1 | public function getTestCount() |
|
100 | } |
||
101 |