1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpUnit\Contract\Command; |
4
|
|
|
|
5
|
|
|
use Bruli\EventBusBundle\CommandBus\CommandHandlerInterface; |
6
|
|
|
use Bruli\EventBusBundle\CommandBus\CommandInterface; |
7
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
8
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
9
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool; |
10
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Exception\PhpUnitViolationException; |
11
|
|
|
use PhpGitHooks\Module\PhpUnit\Model\PhpUnitProcessorInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class PhpUnitToolHandler implements CommandHandlerInterface |
15
|
|
|
{ |
16
|
|
|
const EXECUTING_MESSAGE = 'Running unit tests'; |
17
|
|
|
/** |
18
|
|
|
* @var OutputInterface |
19
|
|
|
*/ |
20
|
|
|
private $output; |
21
|
|
|
/** |
22
|
|
|
* @var PhpUnitProcessorInterface |
23
|
|
|
*/ |
24
|
|
|
private $phpUnitProcessor; |
25
|
|
|
/** |
26
|
|
|
* @var PhpUnitProcessorInterface |
27
|
|
|
*/ |
28
|
|
|
private $phpUnitRandomizerProcessor; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* PhpUnitTool constructor. |
32
|
|
|
* |
33
|
|
|
* @param OutputInterface $output |
34
|
|
|
* @param PhpUnitProcessorInterface $phpUnitProcessor |
35
|
|
|
* @param PhpUnitProcessorInterface $phpUnitRandomizerProcessor |
36
|
|
|
*/ |
37
|
2 |
|
public function __construct( |
38
|
|
|
OutputInterface $output, |
39
|
|
|
PhpUnitProcessorInterface $phpUnitProcessor, |
40
|
|
|
PhpUnitProcessorInterface $phpUnitRandomizerProcessor |
41
|
|
|
) { |
42
|
2 |
|
$this->output = $output; |
43
|
2 |
|
$this->phpUnitProcessor = $phpUnitProcessor; |
44
|
2 |
|
$this->phpUnitRandomizerProcessor = $phpUnitRandomizerProcessor; |
45
|
2 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $randomMode |
49
|
|
|
* @param string $options |
50
|
|
|
* @param string $errorMessage |
51
|
|
|
* |
52
|
|
|
* @throws PhpUnitViolationException |
53
|
|
|
*/ |
54
|
2 |
|
private function execute($randomMode, $options, $errorMessage) |
55
|
|
|
{ |
56
|
2 |
|
$outputMessage = new PreCommitOutputWriter(self::EXECUTING_MESSAGE); |
57
|
2 |
|
$this->output->writeln($outputMessage->getMessage()); |
58
|
|
|
|
59
|
2 |
|
$testResult = $this->executeTool($randomMode, $options); |
|
|
|
|
60
|
|
|
|
61
|
2 |
|
if (false === $testResult) { |
62
|
1 |
|
$this->output->writeln(BadJobLogoResponse::paint($errorMessage)); |
63
|
|
|
|
64
|
1 |
|
throw new PhpUnitViolationException(); |
65
|
|
|
} |
66
|
1 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param bool $randomMode |
70
|
|
|
* @param string $options |
71
|
|
|
* |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
2 |
|
protected function executeTool($randomMode, $options) |
75
|
|
|
{ |
76
|
2 |
|
return true === $randomMode ? $this->phpUnitRandomizerProcessor->process( |
77
|
2 |
|
$options |
78
|
2 |
|
) : $this->phpUnitProcessor->process($options); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param CommandInterface|PhpUnitTool $command |
83
|
|
|
*/ |
84
|
2 |
|
public function handle(CommandInterface $command) |
85
|
|
|
{ |
86
|
2 |
|
$this->execute( |
87
|
2 |
|
$command->isRandomMode(), |
|
|
|
|
88
|
2 |
|
$command->getOptions(), |
|
|
|
|
89
|
2 |
|
$command->getErrorMessage() |
|
|
|
|
90
|
|
|
); |
91
|
1 |
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: