1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpMd\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PhpMdOptionsStub; |
7
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
8
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
9
|
|
|
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub; |
10
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdToolCommand; |
11
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\CommandHandler\PhpMdToolCommandHandler; |
12
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\Exception\PhpMdViolationsException; |
13
|
|
|
use PhpGitHooks\Module\PhpMd\Service\PhpMdTool; |
14
|
|
|
use PhpGitHooks\Module\PhpMd\Tests\Infrastructure\PhpMdUnitTestCase; |
15
|
|
|
|
16
|
|
|
class PhpMdToolCommandHandlerTest extends PhpMdUnitTestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var PhpMdToolCommandHandler |
20
|
|
|
*/ |
21
|
|
|
private $phpMdToolCommandHandler; |
22
|
|
|
|
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->phpMdToolCommandHandler = new PhpMdToolCommandHandler( |
26
|
|
|
new PhpMdTool( |
27
|
|
|
$this->getOutputInterface(), |
|
|
|
|
28
|
|
|
$this->getPhpMdToolProcessor() |
|
|
|
|
29
|
|
|
) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function itShouldThrowsException() |
37
|
|
|
{ |
38
|
|
|
$this->expectException(PhpMdViolationsException::class); |
39
|
|
|
|
40
|
|
|
$phpMdOptions = PhpMdOptionsStub::random(); |
41
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
42
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
43
|
|
|
|
44
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE); |
45
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
46
|
|
|
|
47
|
|
|
$errorsText = null; |
48
|
|
|
foreach ($phpFiles as $phpFile) { |
49
|
|
|
$error = 'ERROR'; |
50
|
|
|
$this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), $error); |
51
|
|
|
$errorsText .= $error; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->shouldWriteLnOutput($outputMessage->getFailMessage()); |
55
|
|
|
$this->shouldWriteLnOutput($outputMessage->setError($errorsText)); |
56
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); |
57
|
|
|
|
58
|
|
|
$command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage); |
59
|
|
|
$this->phpMdToolCommandHandler->handle($command); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @test |
64
|
|
|
*/ |
65
|
|
|
public function itShouldWorksFine() |
66
|
|
|
{ |
67
|
|
|
$phpMdOptions = PhpMdOptionsStub::random(); |
68
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
69
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
70
|
|
|
|
71
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpMdTool::CHECKING_MESSAGE); |
72
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
73
|
|
|
|
74
|
|
|
foreach ($phpFiles as $phpFile) { |
75
|
|
|
$this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), null); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage()); |
79
|
|
|
|
80
|
|
|
$command = new PhpMdToolCommand($phpFiles, $phpMdOptions->value(), $errorMessage); |
81
|
|
|
$this->phpMdToolCommandHandler->handle($command); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.