1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Application\PhpUnit; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Application\Config\HookConfigExtraToolInterface; |
6
|
|
|
use PhpGitHooks\Application\Config\HookConfigInterface; |
7
|
|
|
use PhpGitHooks\Infrastructure\Common\PreCommitExecutor; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class UnitTestPreCommitExecutor extends PreCommitExecutor |
11
|
|
|
{ |
12
|
|
|
const TOOL = 'phpunit'; |
13
|
|
|
const ENABLED_KEY = 'enabled'; |
14
|
|
|
const RANDOM_MODE_KEY = 'random-mode'; |
15
|
|
|
const SUITE_KEY = 'suite'; |
16
|
|
|
/** @var PhpUnitHandler */ |
17
|
|
|
private $phpunitHandler; |
18
|
|
|
/** @var PhpUnitRandomizerHandler */ |
19
|
|
|
private $phpUnitRandomizerHandler; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param HookConfigInterface $hookConfigInterface |
23
|
|
|
* @param PhpUnitHandler $phpUnitHandler |
24
|
|
|
* @param PhpUnitRandomizerHandler $phpUnitRandomizerHandler |
25
|
|
|
*/ |
26
|
4 |
|
public function __construct( |
27
|
|
|
HookConfigInterface $hookConfigInterface, |
28
|
|
|
PhpUnitHandler $phpUnitHandler, |
29
|
|
|
PhpUnitRandomizerHandler $phpUnitRandomizerHandler |
30
|
|
|
) { |
31
|
4 |
|
$this->preCommitConfig = $hookConfigInterface; |
32
|
4 |
|
$this->phpunitHandler = $phpUnitHandler; |
33
|
4 |
|
$this->phpUnitRandomizerHandler = $phpUnitRandomizerHandler; |
34
|
4 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param OutputInterface $outputInterface |
38
|
|
|
* |
39
|
|
|
* @throws UnitTestsException |
40
|
|
|
*/ |
41
|
4 |
|
public function run(OutputInterface $outputInterface) |
42
|
|
|
{ |
43
|
|
|
/** @var HookConfigExtraToolInterface $data */ |
44
|
4 |
|
$data = $this->preCommitConfig; |
45
|
4 |
|
$extraOptions = $data->extraOptions(PhpUnitConfigData::TOOL); |
46
|
4 |
|
if (true === $extraOptions[self::ENABLED_KEY]) { |
47
|
3 |
|
if (true === $extraOptions[self::RANDOM_MODE_KEY]) { |
48
|
1 |
|
if ($extraOptions[self::SUITE_KEY]) { |
49
|
|
|
$this->phpUnitRandomizerHandler->setSuite($extraOptions[self::SUITE_KEY]); |
50
|
|
|
} |
51
|
|
|
$this->phpUnitRandomizerHandler->setOutput($outputInterface); |
52
|
|
|
$this->phpUnitRandomizerHandler->run($this->getMessages()); |
53
|
|
|
} else { |
54
|
3 |
|
if ($extraOptions[self::SUITE_KEY]) { |
55
|
1 |
|
$this->phpunitHandler->setSuite($extraOptions[self::SUITE_KEY]); |
56
|
1 |
|
} |
57
|
3 |
|
$this->phpunitHandler->setOutput($outputInterface); |
58
|
3 |
|
$this->phpunitHandler->run($this->getMessages()); |
59
|
|
|
} |
60
|
2 |
|
} |
61
|
3 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
protected function commandName() |
67
|
|
|
{ |
68
|
|
|
return self::TOOL; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|