forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreCommitToolHandlerTest.php
More file actions
133 lines (121 loc) · 5.51 KB
/
PreCommitToolHandlerTest.php
File metadata and controls
133 lines (121 loc) · 5.51 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace PhpGitHooks\Module\Git\Tests\Behaviour;
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool;
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinder;
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub;
use PhpGitHooks\Module\Files\Contract\Query\PhpFilesExtractor;
use PhpGitHooks\Module\Files\Tests\Stub\PhpFilesResponseStub;
use PhpGitHooks\Module\Git\Contract\Command\PreCommitTool;
use PhpGitHooks\Module\Git\Contract\Command\PreCommitToolHandler;
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse;
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase;
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintTool;
use PhpGitHooks\Module\PhpCs\Contract\Command\PhpCsTool;
use PhpGitHooks\Module\PhpCsFixer\Contract\Command\PhpCsFixerTool;
use PhpGitHooks\Module\PhpLint\Contract\Command\PhpLintTool;
use PhpGitHooks\Module\PhpMd\Contract\Command\PhpMdTool;
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverage;
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool;
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverage;
use PhpGitHooks\Module\Tests\Infrastructure\Stub\StubCreator;
class PreCommitToolHandlerTest extends GitUnitTestCase
{
/**
* @var PreCommitToolHandler
*/
private $preCommitToolCommandHandler;
protected function setUp(): void
{
$this->preCommitToolCommandHandler = new PreCommitToolHandler(
$this->getOutputInterface(),
$this->getFilesCommittedExtractor(),
$this->getQueryBus(),
$this->getCommandBus(),
$this->getToolTitleOutputWriter()
);
}
/**
* @test
*/
public function itShouldNotExecuteTools()
{
$this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title');
$this->shouldGetFilesCommitted([StubCreator::faker()->sha1]);
$this->shouldWriteLnOutput(PreCommitToolHandler::NO_FILES_CHANGED_MESSAGE);
$this->preCommitToolCommandHandler->handle(new PreCommitTool());
}
/**
* @test
*/
public function itShouldExecuteAllTools()
{
$files = FilesCommittedStub::createAllFiles();
$configurationDataResponse = ConfigurationDataResponseStub::createAllEnabled();
$this->shouldWriteTitle(PreCommitToolHandler::TITLE, 'title');
$this->shouldGetFilesCommitted($files);
$this->shouldHandleQuery(new ConfigurationDataFinder(), $configurationDataResponse);
$this->shouldHandleCommand(
new ComposerTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
);
$this->shouldHandleCommand(
new JsonLintTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
);
$this->shouldHandleQuery(
new PhpFilesExtractor($files),
PhpFilesResponseStub::create(FilesCommittedStub::createWithoutPhpFiles())
);
$this->shouldHandleCommand(
new PhpLintTool($files, $configurationDataResponse->getPreCommit()->getErrorMessage())
);
$this->shouldHandleCommand(
new PhpCsTool(
$files,
$configurationDataResponse->getPreCommit()->getPhpCs()->getPhpCsStandard(),
HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT,
$configurationDataResponse->getPreCommit()->getPhpCs()->getIgnore()
)
);
$this->shouldHandleCommand(
new PhpCsFixerTool(
$files,
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr0(),
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr1(),
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerPsr2(),
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->isPhpCsFixerSymfony(),
$configurationDataResponse->getPreCommit()->getPhpCsFixer()->getPhpCsFixerOptions(),
$configurationDataResponse->getPreCommit()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new PhpMdTool(
$files,
$configurationDataResponse->getPreCommit()->getPhpMd()->getPhpMdOptions(),
$configurationDataResponse->getPreCommit()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new PhpUnitTool(
$configurationDataResponse->getPreCommit()->getPhpUnit()->isPhpunitRandomMode(),
$configurationDataResponse->getPreCommit()->getPhpUnit()->getPhpunitOptions(),
$configurationDataResponse->getPreCommit()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new StrictCoverage(
$configurationDataResponse->getPreCommit()->getPhpUnitStrictCoverage()->getMinimum(),
$configurationDataResponse->getPreCommit()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new GuardCoverage(
$configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage()
)
);
$this->shouldWriteLnOutput(
GoodJobLogoResponse::paint($configurationDataResponse->getPreCommit()->getRightMessage())
);
$this->preCommitToolCommandHandler->handle(new PreCommitTool());
}
}