forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonLintToolHandlerTest.php
More file actions
114 lines (95 loc) · 3.53 KB
/
JsonLintToolHandlerTest.php
File metadata and controls
114 lines (95 loc) · 3.53 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace PhpGitHooks\Module\JsonLint\Tests\Behaviour;
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
use PhpGitHooks\Module\Files\Contract\Query\JsonFilesExtractor;
use PhpGitHooks\Module\Files\Tests\Stub\JsonFilesResponseStub;
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintTool;
use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintToolHandler;
use PhpGitHooks\Module\JsonLint\Contract\Exception\JsonLintViolationsException;
use PhpGitHooks\Module\JsonLint\Service\JsonLintToolExecutor;
use PhpGitHooks\Module\JsonLint\Tests\Infrastructure\JsonLintUnitTestCase;
class JsonLintToolHandlerTest extends JsonLintUnitTestCase
{
/**
* @var JsonLintToolHandler
*/
private $jsonLintToolCommandHandler;
/**
* @var string
*/
private $errorMessage;
protected function setUp(): void
{
$this->jsonLintToolCommandHandler = new JsonLintToolHandler(
new JsonLintToolExecutor(
$this->getJsonLintProcessor(),
$this->getOutputInterface()
),
$this->getQueryBus()
);
$this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
}
/**
* @test
*/
public function itShouldNotExecuteTool()
{
$files = FilesCommittedStub::createWithoutJsonFiles();
$this->shouldHandleQuery(
new JsonFilesExtractor($files),
JsonFilesResponseStub::createNoData()
);
$this->jsonLintToolCommandHandler->handle(
new JsonLintTool($files, $this->errorMessage)
);
}
/**
* @test
*/
public function itShouldExecuteTool()
{
$files = JsonFilesResponseStub::createWithJsonData();
$output = new PreCommitOutputWriter(JsonLintToolExecutor::CHECKING_MESSAGE);
$this->shouldHandleQuery(
new JsonFilesExtractor($files->getFiles()),
$files
);
$this->shouldWriteOutput($output->getMessage());
foreach ($files->getFiles() as $file) {
$this->shouldProcessJsonLint($file, null);
}
$this->shouldWriteLnOutput($output->getSuccessfulMessage());
$this->jsonLintToolCommandHandler->handle(
new JsonLintTool($files->getFiles(), $this->errorMessage)
);
}
/**
* @test
*/
public function itShouldThrowsException()
{
$this->expectException(JsonLintViolationsException::class);
$output = new PreCommitOutputWriter(JsonLintToolExecutor::CHECKING_MESSAGE);
$jsonFilesResponse = JsonFilesResponseStub::createWithJsonData();
$this->shouldHandleQuery(
new JsonFilesExtractor($jsonFilesResponse->getFiles()),
$jsonFilesResponse
);
$this->shouldWriteOutput($output->getMessage());
$errorTxt = null;
foreach ($jsonFilesResponse->getFiles() as $file) {
$error = 'ERROR';
$this->shouldProcessJsonLint($file, $error);
$errorTxt .= $error;
}
$this->shouldWriteLnOutput($output->getFailMessage());
$this->shouldWriteLnOutput($output->setError($errorTxt));
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
$this->jsonLintToolCommandHandler->handle(
new JsonLintTool($jsonFilesResponse->getFiles(), $this->errorMessage)
);
}
}