|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SugaredRim\PHPUnit\TextUI; |
|
4
|
|
|
|
|
5
|
|
|
use Psr\Log\LoggerInterface; |
|
6
|
|
|
use Schnittstabil\ComposerExtra\ComposerExtra; |
|
7
|
|
|
use Schnittstabil\Get\Get; |
|
8
|
|
|
|
|
9
|
|
|
class BaseCommand extends \PHPUnit\TextUI\Command |
|
10
|
|
|
{ |
|
11
|
|
|
protected $argvRendererClass = Argv::class; |
|
12
|
|
|
protected $namespace = 'sugared-rim/phpunit'; |
|
13
|
|
|
protected $defaultConfig; |
|
14
|
|
|
protected $logger; |
|
15
|
|
|
protected $config; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function __construct(LoggerInterface $logger = null) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->defaultConfig = new \stdClass(); |
|
23
|
|
|
$this->defaultConfig->presets = ['SugaredRim\\PHPUnit\\DefaultPreset::get']; |
|
24
|
|
|
|
|
25
|
|
|
$this->logger = $logger; |
|
26
|
|
|
|
|
27
|
|
|
$this->longOptions['sugared-coverage-text-show-uncovered-files'] |
|
28
|
|
|
= 'sugaredCoverageTextShowUncoveredFilesHandler'; |
|
29
|
|
|
$this->longOptions['sugared-debug'] = 'sugaredDebugHandler'; |
|
30
|
|
|
$this->longOptions['sugared-namespace='] = 'sugaredNamespaceHandler'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function logDebug($title, $value) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->logger !== null) { |
|
36
|
|
|
$this->logger->debug($title.': '.json_encode($value, JSON_PRETTY_PRINT)); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function sugaredCoverageTextShowUncoveredFilesHandler() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->arguments['coverageTextShowUncoveredFiles'] = true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function sugaredDebugHandler() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->arguments['sugaredDebug'] = true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function sugaredNamespaceHandler($namespace) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->namespace = $namespace; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function addListeners() |
|
59
|
|
|
{ |
|
60
|
|
|
foreach ((array) $this->getConfig('sugared.listeners', []) as $listener) { |
|
61
|
|
|
$class = Get::value('class', $listener); |
|
62
|
|
|
$listenerClass = new \ReflectionClass($class); |
|
63
|
|
|
$arguments = json_decode(json_encode(Get::value('arguments', $listener, [])), true); |
|
64
|
|
|
|
|
65
|
|
|
$this->arguments['listeners'][] = $listenerClass->newInstanceArgs($arguments); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function getConfig($path = null, $default = null) |
|
70
|
|
|
{ |
|
71
|
|
|
if ($this->config === null) { |
|
72
|
|
|
$this->config = new ComposerExtra( |
|
73
|
|
|
$this->namespace, |
|
74
|
|
|
$this->defaultConfig, |
|
75
|
|
|
'presets' |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($path === null) { |
|
80
|
|
|
$path = array(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $this->config->get($path, $default); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function preprocessArgv(array $argv) |
|
87
|
|
|
{ |
|
88
|
|
|
$config = $this->getConfig(); |
|
89
|
|
|
|
|
90
|
|
|
if (in_array('--sugared-debug', $argv)) { |
|
91
|
|
|
$this->logDebug('Config', $config); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$argvRenderer = new $this->argvRendererClass($config); |
|
95
|
|
|
|
|
96
|
|
|
return $argvRenderer($argv); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|