1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Composer\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Composer\Contract\Command\ComposerTool; |
6
|
|
|
use PhpGitHooks\Module\Composer\Contract\Command\ComposerToolHandler; |
7
|
|
|
use PhpGitHooks\Module\Composer\Contract\Exception\ComposerFilesNotFoundException; |
8
|
|
|
use PhpGitHooks\Module\Composer\Tests\Infrastructure\ComposerUnitTestCase; |
9
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub; |
10
|
|
|
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractor; |
11
|
|
|
use PhpGitHooks\Module\Files\Tests\Stub\ComposerFilesResponseStub; |
12
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
13
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
14
|
|
|
use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub; |
15
|
|
|
|
16
|
|
|
class ComposerToolHandlerTest extends ComposerUnitTestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ComposerToolHandler |
20
|
|
|
*/ |
21
|
|
|
private $composerToolCommandHandler; |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $errorMessage; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE; |
30
|
|
|
$this->composerToolCommandHandler = new ComposerToolHandler( |
31
|
|
|
$this->getQueryBus(), |
|
|
|
|
32
|
|
|
$this->getOutputInterface() |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @test |
38
|
|
|
*/ |
39
|
|
|
public function itShouldWorksFine() |
40
|
|
|
{ |
41
|
|
|
$files = FilesCommittedStub::createAllFiles(); |
42
|
|
|
|
43
|
|
|
$output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE); |
44
|
|
|
$this->shouldWriteOutput($output->getMessage()); |
45
|
|
|
$this->shouldHandleQuery( |
46
|
|
|
new ComposerFilesExtractor($files), |
47
|
|
|
ComposerFilesResponseStub::createValidData() |
48
|
|
|
); |
49
|
|
|
$this->shouldWriteLnOutput($output->getSuccessfulMessage()); |
50
|
|
|
|
51
|
|
|
$this->composerToolCommandHandler->handle( |
52
|
|
|
new ComposerTool($files, $this->errorMessage) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
|
public function itShouldThrowException() |
60
|
|
|
{ |
61
|
|
|
$this->expectException(ComposerFilesNotFoundException::class); |
62
|
|
|
|
63
|
|
|
$files = FilesCommittedStub::createInvalidComposerFiles(); |
64
|
|
|
$output = new PreCommitOutputWriter(ComposerToolHandler::CHECKING_MESSAGE); |
65
|
|
|
|
66
|
|
|
$this->shouldWriteOutput($output->getMessage()); |
67
|
|
|
$this->shouldHandleQuery( |
68
|
|
|
new ComposerFilesExtractor($files), |
69
|
|
|
ComposerFilesResponseStub::createInvalidData() |
70
|
|
|
); |
71
|
|
|
$this->shouldWriteLnOutput($output->getFailMessage()); |
72
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); |
73
|
|
|
|
74
|
|
|
$this->composerToolCommandHandler->handle( |
75
|
|
|
new ComposerTool($files, $this->errorMessage) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @test |
81
|
|
|
*/ |
82
|
|
|
public function itShouldNotExecuteComposerTool() |
83
|
|
|
{ |
84
|
|
|
$files = FilesCommittedStub::createWithoutComposerFiles(); |
85
|
|
|
|
86
|
|
|
$this->shouldHandleQuery( |
87
|
|
|
new ComposerFilesExtractor($files), |
88
|
|
|
ComposerFilesResponseStub::createNoData() |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$this->composerToolCommandHandler->handle(new ComposerTool($files, $this->errorMessage)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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.