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