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\PhpMdTool; |
11
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdToolHandler; |
12
|
|
|
use PhpGitHooks\Module\PhpMd\Contract\Exception\PhpMdViolationsException; |
13
|
|
|
use PhpGitHooks\Module\PhpMd\Tests\Infrastructure\PhpMdUnitTestCase; |
14
|
|
|
|
15
|
|
|
class PhpMdToolHandlerTest extends PhpMdUnitTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PhpMdToolHandler |
19
|
|
|
*/ |
20
|
|
|
private $phpMdToolCommandHandler; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->phpMdToolCommandHandler = new PhpMdToolHandler( |
25
|
|
|
$this->getOutputInterface(), |
26
|
|
|
$this->getPhpMdToolProcessor() |
|
|
|
|
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function itShouldThrowsException() |
34
|
|
|
{ |
35
|
|
|
$this->expectException(PhpMdViolationsException::class); |
36
|
|
|
|
37
|
|
|
$phpMdOptions = PhpMdOptionsStub::random(); |
38
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
39
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
40
|
|
|
|
41
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpMdToolHandler::CHECKING_MESSAGE); |
42
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
43
|
|
|
|
44
|
|
|
$errorsText = null; |
45
|
|
|
foreach ($phpFiles as $phpFile) { |
46
|
|
|
$error = 'ERROR'; |
47
|
|
|
$this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), $error); |
48
|
|
|
$errorsText .= $error; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->shouldWriteLnOutput($outputMessage->getFailMessage()); |
52
|
|
|
$this->shouldWriteLnOutput($outputMessage->setError($errorsText)); |
53
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); |
54
|
|
|
|
55
|
|
|
$command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage); |
56
|
|
|
$this->phpMdToolCommandHandler->handle($command); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function itShouldWorksFine() |
63
|
|
|
{ |
64
|
|
|
$phpMdOptions = PhpMdOptionsStub::random(); |
65
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
66
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
67
|
|
|
|
68
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpMdToolHandler::CHECKING_MESSAGE); |
69
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
70
|
|
|
|
71
|
|
|
foreach ($phpFiles as $phpFile) { |
72
|
|
|
$this->shouldProcessPhpMdTool($phpFile, $phpMdOptions->value(), null); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage()); |
76
|
|
|
|
77
|
|
|
$command = new PhpMdTool($phpFiles, $phpMdOptions->value(), $errorMessage); |
78
|
|
|
$this->phpMdToolCommandHandler->handle($command); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.