forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComposerToolHandlerTest.php
More file actions
93 lines (79 loc) · 2.97 KB
/
ComposerToolHandlerTest.php
File metadata and controls
93 lines (79 loc) · 2.97 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
<?php
namespace PhpGitHooks\Module\Composer\Tests\Behaviour;
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool;
use PhpGitHooks\Module\Composer\Contract\Command\ComposerToolHandler;
use PhpGitHooks\Module\Composer\Contract\Exception\ComposerFilesNotFoundException;
use PhpGitHooks\Module\Composer\Tests\Infrastructure\ComposerUnitTestCase;
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub;
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractor;
use PhpGitHooks\Module\Files\Tests\Stub\ComposerFilesResponseStub;
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub;
class ComposerToolHandlerTest extends ComposerUnitTestCase
{
/**
* @var ComposerToolHandler
*/
private $composerToolCommandHandler;
/**
* @var string
*/
private $errorMessage;
protected function setUp(): void
{
$this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE;
$this->composerToolCommandHandler = new ComposerToolHandler(
$this->getQueryBus(),
$this->getOutputInterface()
);
}
/**
* @test
*/
public function itShouldWorksFine()
{
$files = FilesCommittedStub::createAllFiles();
$output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE);
$this->shouldWriteOutput($output->getMessage());
$this->shouldHandleQuery(
new ComposerFilesExtractor($files),
ComposerFilesResponseStub::createValidData()
);
$this->shouldWriteLnOutput($output->getSuccessfulMessage());
$this->composerToolCommandHandler->handle(
new ComposerTool($files, $this->errorMessage)
);
}
/**
* @test
*/
public function itShouldThrowException()
{
$this->expectException(ComposerFilesNotFoundException::class);
$files = FilesCommittedStub::createInvalidComposerFiles();
$output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE);
$this->shouldWriteOutput($output->getMessage());
$this->shouldHandleQuery(
new ComposerFilesExtractor($files),
ComposerFilesResponseStub::createInvalidData()
);
$this->shouldWriteLnOutput($output->getFailMessage());
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage));
$this->composerToolCommandHandler->handle(
new ComposerTool($files, $this->errorMessage)
);
}
/**
* @test
*/
public function itShouldNotExecuteComposerTool()
{
$files = FilesCommittedStub::createWithoutComposerFiles();
$this->shouldHandleQuery(
new ComposerFilesExtractor($files),
ComposerFilesResponseStub::createNoData()
);
$this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage));
}
}