1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpCs\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
6
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
7
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
8
|
|
|
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub; |
9
|
|
|
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsToolCommand; |
10
|
|
|
use PhpGitHooks\Module\PhpCs\Contract\CommandHandler\PhpCsToolCommandHandler; |
11
|
|
|
use PhpGitHooks\Module\PhpCs\Contract\Exception\PhpCsViolationException; |
12
|
|
|
use PhpGitHooks\Module\PhpCs\Service\PhpCsTool; |
13
|
|
|
use PhpGitHooks\Module\PhpCs\Tests\Infrastructure\PhpCsUnitTestCase; |
14
|
|
|
|
15
|
|
|
class PhpCsToolCommandHandlerTest extends PhpCsUnitTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PhpCsToolCommandHandler |
19
|
|
|
*/ |
20
|
|
|
private $phpCsToolCommandHandler; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->phpCsToolCommandHandler = new PhpCsToolCommandHandler( |
25
|
|
|
new PhpCsTool( |
26
|
|
|
$this->getOutputInterface(), |
|
|
|
|
27
|
|
|
$this->getPhpCsToolProcessor() |
|
|
|
|
28
|
|
|
) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
*/ |
35
|
|
|
public function itShouldThrowsException() |
36
|
|
|
{ |
37
|
|
|
$this->expectException(PhpCsViolationException::class); |
38
|
|
|
|
39
|
|
|
$output = new PreCommitOutputWriter(PhpCsTool::EXECUTE_MESSAGE); |
40
|
|
|
$files = FilesCommittedStub::createOnlyPhpFiles(); |
41
|
|
|
|
42
|
|
|
$this->shouldWriteOutput($output->getMessage()); |
43
|
|
|
|
44
|
|
|
$errorTxt = null; |
45
|
|
|
foreach ($files as $file) { |
46
|
|
|
$error = 'ERROR-'; |
47
|
|
|
$this->shouldProcessPhpCsTool($file, 'PSR2', $error); |
48
|
|
|
$errorTxt .= $error; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->shouldWriteLnOutput($output->getFailMessage()); |
52
|
|
|
$this->shouldWriteLnOutput($output->setError($errorTxt)); |
53
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint(HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)); |
54
|
|
|
|
55
|
|
|
$this->phpCsToolCommandHandler->handle( |
56
|
|
|
new PhpCsToolCommand( |
57
|
|
|
$files, |
58
|
|
|
'PSR2', |
59
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function itShouldWorksFine() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$output = new PreCommitOutputWriter(PhpCsTool::EXECUTE_MESSAGE); |
70
|
|
|
$files = FilesCommittedStub::createOnlyPhpFiles(); |
71
|
|
|
|
72
|
|
|
$this->shouldWriteOutput($output->getMessage()); |
73
|
|
|
|
74
|
|
|
foreach ($files as $file) { |
75
|
|
|
$this->shouldProcessPhpCsTool($file, 'PSR2', null); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->shouldWriteLnOutput($output->getSuccessfulMessage()); |
79
|
|
|
|
80
|
|
|
$this->phpCsToolCommandHandler->handle( |
81
|
|
|
new PhpCsToolCommand( |
82
|
|
|
$files, |
83
|
|
|
'PSR2', |
84
|
|
|
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT |
85
|
|
|
) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.