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