1
|
|
|
<?php namespace ParaTest\Runners\PHPUnit; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class TestMethod |
5
|
|
|
* |
6
|
|
|
* Represents a set of tests grouped in batch which can be passed to a single phpunit process. |
7
|
|
|
* Batch limited to run tests only from one php test case file. |
8
|
|
|
* Used for running ParaTest in functional mode. |
9
|
|
|
* |
10
|
|
|
* @todo Rename to Batch |
11
|
|
|
* |
12
|
|
|
* @package ParaTest\Runners\PHPUnit |
13
|
|
|
*/ |
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) |
40
|
|
|
{ |
41
|
21 |
|
$this->path = $testPath; |
42
|
|
|
// for compatibility with other code (tests), which can pass string (one filter) |
43
|
|
|
// instead of array of filters |
44
|
21 |
|
$this->filters = (array)$filters; |
45
|
21 |
|
} |
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() |
65
|
|
|
{ |
66
|
3 |
|
return implode("|", $this->filters); |
67
|
|
|
} |
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
|
|
|
* @return array |
77
|
|
|
*/ |
78
|
|
|
protected function prepareOptions($options) |
79
|
|
|
{ |
80
|
|
|
$re = array_reduce($this->filters, function ($r, $v) { |
81
|
|
|
$isDataSet = strpos($v, " with data set ") !== false; |
82
|
|
|
return ($r ? $r . "|" : "") . preg_quote($v, "/") . ($isDataSet ? "\$" : "(?:\s|\$)"); |
83
|
|
|
}); |
84
|
|
|
$options['filter'] = "/" . $re . "/"; |
85
|
|
|
|
86
|
|
|
return $options; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the expected count of tests to be executed. |
91
|
|
|
* |
92
|
|
|
* @return int |
93
|
|
|
*/ |
94
|
1 |
|
public function getTestCount() |
95
|
|
|
{ |
96
|
1 |
|
return count($this->filters); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|