1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SugaredRim\PHPUnit\TextUI; |
4
|
|
|
|
5
|
|
|
use Schnittstabil\Get\Get; |
6
|
|
|
|
7
|
|
|
class Argv |
8
|
|
|
{ |
9
|
|
|
protected $config; |
10
|
|
|
|
11
|
|
|
public function __construct($config) |
12
|
|
|
{ |
13
|
|
|
$this->config = $config; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
18
|
|
|
*/ |
19
|
|
|
protected function renderWhitelist($argv) |
20
|
|
|
{ |
21
|
|
|
$src = Get::value('src', $this->config, false); |
22
|
|
|
|
23
|
|
|
if (empty($src)) { |
24
|
|
|
throw new \InvalidArgumentException( |
25
|
|
|
sprintf('"src" option is not configured, code coverage is not possible.', $src) |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if (!is_dir($src)) { |
30
|
|
|
throw new \InvalidArgumentException( |
31
|
|
|
sprintf('"%s" directory could not be found.', $src) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$argv[] = '--whitelist='.$src; |
36
|
|
|
|
37
|
|
|
return $argv; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
42
|
|
|
*/ |
43
|
|
|
protected function renderCoverage($argv) |
44
|
|
|
{ |
45
|
|
|
$coverage = Get::value('coverage', $this->config, false); |
46
|
|
|
|
47
|
|
|
if (empty($coverage)) { |
48
|
|
|
return $argv; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$includesText = false; |
52
|
|
|
$withCoverage = false; |
53
|
|
|
|
54
|
|
|
foreach ($coverage as $k => $v) { |
55
|
|
|
if (!empty($v)) { |
56
|
|
|
$argv[] = '--coverage-'.$k.'='.$v; |
57
|
|
|
$includesText = $includesText || $k === 'text'; |
58
|
|
|
$withCoverage = true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($withCoverage) { |
63
|
|
|
$argv = $this->renderWhitelist($argv); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($includesText && Get::value('sugared.coverage-text-show-uncovered-files', $this->config)) { |
67
|
|
|
$argv[] = '--sugared-coverage-text-show-uncovered-files'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $argv; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Render argv array. |
75
|
|
|
* |
76
|
|
|
* @param array $argv |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
* |
80
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
81
|
|
|
*/ |
82
|
|
|
public function __invoke(array $argv) |
83
|
|
|
{ |
84
|
|
|
$script = array_shift($argv); |
85
|
|
|
|
86
|
|
|
$argv = $this->renderCoverage($argv); |
87
|
|
|
|
88
|
|
|
if (Get::value('sugared.debug', $this->config)) { |
89
|
|
|
$argv[] = '--sugared-debug'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (Get::value('colors', $this->config)) { |
93
|
|
|
$argv[] = '--colors'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ($bootstrap = Get::value('bootstrap', $this->config)) { |
97
|
|
|
$argv[] = '--bootstrap='.$bootstrap; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$positionalArgs = array_filter( |
101
|
|
|
$argv, |
102
|
|
|
function ($arg) { |
103
|
|
|
return substr($arg, 0, 1) !== '-'; |
104
|
|
|
} |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
if (empty($positionalArgs)) { |
108
|
|
|
$tests = Get::value('tests', $this->config, false); |
109
|
|
|
if ($tests) { |
110
|
|
|
$argv[] = $tests; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
array_unshift($argv, $script); |
115
|
|
|
|
116
|
|
|
return $argv; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|