forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpLintToolHandlerTest.php
More file actions
79 lines (64 loc) · 2.55 KB
/
PhpLintToolHandlerTest.php
File metadata and controls
79 lines (64 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace PhpGitHooks\Module\PhpLint\Tests\Behaviour;
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintTool;
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintToolHandler;
use PhpGitHooks\Module\PhpLint\Contract\Exception\PhpLintViolationsException;
use PhpGitHooks\Module\PhpLint\Tests\Infrastructure\PhpLintUnitTestCase;
class PhpLintToolHandlerTest extends PhpLintUnitTestCase
{
/**
* @var PhpLintToolHandler
*/
private $phpLintToolCommandHandler;
protected function setUp(): void
{
$this->phpLintToolCommandHandler = new PhpLintToolHandler(
$this->getPhpLintToolProcessor(),
$this->getOutputInterface()
);
}
/**
* @test
*/
public function itShouldThrowsException()
{
$this->expectException(PhpLintViolationsException::class);
$phpFiles = FilesCommittedStub::createOnlyPhpFiles();
$outputMessage = new PreCommitOutputWriter(PhpLintToolHandler::RUNNING_PHPLINT);
$errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
$this->shouldWriteOutput($outputMessage->getMessage());
$errors = null;
foreach ($phpFiles as $file) {
$error = 'ERROR';
$this->shouldProcessPhpLintTool($file, $error);
$errors .= $error;
}
$this->shouldWriteLnOutput($outputMessage->getFailMessage());
$this->shouldWriteLnOutput($outputMessage->setError($errors));
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage));
$this->phpLintToolCommandHandler->handle(
new PhpLintTool($phpFiles, $errorMessage)
);
}
/**
* @test
*/
public function itShouldWorksFine()
{
$phpFiles = FilesCommittedStub::createOnlyPhpFiles();
$outputMessage = new PreCommitOutputWriter(PhpLintToolHandler::RUNNING_PHPLINT);
$this->shouldWriteOutput($outputMessage->getMessage());
foreach ($phpFiles as $file) {
$this->shouldProcessPhpLintTool($file, null);
}
$this->shouldWriteLnOutput($outputMessage->getSuccessfulMessage());
$this->phpLintToolCommandHandler->handle(
new PhpLintTool($phpFiles, HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT)
);
}
}