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
|
|
|
/** @var PhpUnitHandler */ |
13
|
|
|
private $phpunitHandler; |
14
|
|
|
/** @var PhpUnitRandomizerHandler */ |
15
|
|
|
private $phpUnitRandomizerHandler; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param HookConfigInterface $hookConfigInterface |
19
|
|
|
* @param PhpUnitHandler $phpUnitHandler |
20
|
|
|
* @param PhpUnitRandomizerHandler $phpUnitRandomizerHandler |
21
|
|
|
*/ |
22
|
3 |
|
public function __construct( |
23
|
|
|
HookConfigInterface $hookConfigInterface, |
24
|
|
|
PhpUnitHandler $phpUnitHandler, |
25
|
|
|
PhpUnitRandomizerHandler $phpUnitRandomizerHandler |
26
|
|
|
) { |
27
|
3 |
|
$this->preCommitConfig = $hookConfigInterface; |
28
|
3 |
|
$this->phpunitHandler = $phpUnitHandler; |
29
|
3 |
|
$this->phpUnitRandomizerHandler = $phpUnitRandomizerHandler; |
30
|
3 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param OutputInterface $outputInterface |
34
|
|
|
* |
35
|
|
|
* @throws UnitTestsException |
36
|
|
|
*/ |
37
|
3 |
|
public function run(OutputInterface $outputInterface) |
38
|
|
|
{ |
39
|
|
|
/** @var HookConfigExtraToolInterface $data */ |
40
|
3 |
|
$data = $this->preCommitConfig; |
41
|
3 |
|
$extraOptions = $data->extraOptions(PhpUnitConfigData::TOOL); |
42
|
3 |
|
if (true === $extraOptions['enabled']) { |
43
|
2 |
|
if (true === $extraOptions['random-mode']) { |
44
|
|
|
$this->phpUnitRandomizerHandler->setOutput($outputInterface); |
45
|
|
|
$this->phpUnitRandomizerHandler->run($this->getMessages()); |
46
|
|
|
} else { |
47
|
2 |
|
$this->phpunitHandler->setOutput($outputInterface); |
48
|
2 |
|
$this->phpunitHandler->run($this->getMessages()); |
49
|
|
|
} |
50
|
1 |
|
} |
51
|
2 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
protected function commandName() |
57
|
|
|
{ |
58
|
|
|
return 'phpunit'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|