1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpLint\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub; |
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\PhpLint\Contract\Command\PhpLintTool; |
11
|
|
|
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintToolHandler; |
12
|
|
|
use PhpGitHooks\Module\PhpLint\Contract\Exception\PhpLintViolationsException; |
13
|
|
|
use PhpGitHooks\Module\PhpLint\Tests\Infrastructure\PhpLintUnitTestCase; |
14
|
|
|
|
15
|
|
|
class PhpLintToolHandlerTest extends PhpLintUnitTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PhpLintToolHandler |
19
|
|
|
*/ |
20
|
|
|
private $phpLintToolCommandHandler; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->phpLintToolCommandHandler = new PhpLintToolHandler( |
25
|
|
|
$this->getPhpLintToolProcessor(), |
|
|
|
|
26
|
|
|
$this->getOutputInterface() |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @test |
32
|
|
|
*/ |
33
|
|
|
public function itShouldThrowsException() |
34
|
|
|
{ |
35
|
|
|
$this->expectException(PhpLintViolationsException::class); |
36
|
|
|
|
37
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
38
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpLintToolHandler::RUNNING_PHPLINT); |
39
|
|
|
$errorMessage = PreCommitResponseStub::FIX_YOUR_CODE; |
40
|
|
|
|
41
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
42
|
|
|
|
43
|
|
|
$errors = null; |
44
|
|
|
foreach ($phpFiles as $file) { |
45
|
|
|
$error = 'ERROR'; |
46
|
|
|
$this->shouldProcessPhpLintTool($file, $error); |
47
|
|
|
$errors .= $error; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->shouldWriteLnOutput($outputMessage->getFailMessage()); |
51
|
|
|
$this->shouldWriteLnOutput($outputMessage->setError($errors)); |
52
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); |
53
|
|
|
|
54
|
|
|
$this->phpLintToolCommandHandler->handle( |
55
|
|
|
new PhpLintTool($phpFiles, $errorMessage) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function itShouldWorksFine() |
63
|
|
|
{ |
64
|
|
|
$phpFiles = FilesCommittedStub::createOnlyPhpFiles(); |
65
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpLintToolHandler::RUNNING_PHPLINT); |
66
|
|
|
|
67
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
68
|
|
|
|
69
|
|
|
foreach ($phpFiles as $file) { |
70
|
|
|
$this->shouldProcessPhpLintTool($file, null); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage()); |
74
|
|
|
|
75
|
|
|
$this->phpLintToolCommandHandler->handle( |
76
|
|
|
new PhpLintTool($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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.