1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Git\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinderQuery; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub; |
7
|
|
|
use PhpGitHooks\Module\Git\Contract\Command\PrePushToolCommand; |
8
|
|
|
use PhpGitHooks\Module\Git\Contract\CommandHandler\PrePushToolCommandHandler; |
9
|
|
|
use PhpGitHooks\Module\Git\Contract\Exception\InvalidPushException; |
10
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
11
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse; |
12
|
|
|
use PhpGitHooks\Module\Git\Service\PrePushTool; |
13
|
|
|
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase; |
14
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand; |
15
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolCommand; |
16
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageCommand; |
17
|
|
|
|
18
|
|
|
class PrePushToolCommandHandlerTest extends GitUnitTestCase |
19
|
|
|
{ |
20
|
|
|
private $remote = 'origin'; |
21
|
|
|
private $url = '[email protected]'; |
22
|
|
|
/** |
23
|
|
|
* @var PrePushToolCommandHandler |
24
|
|
|
*/ |
25
|
|
|
private $prePushToolCommandHandler; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->prePushToolCommandHandler = new PrePushToolCommandHandler( |
30
|
|
|
new PrePushTool( |
31
|
|
|
$this->getQueryBus(), |
|
|
|
|
32
|
|
|
$this->getPrePushOriginalExecutor(), |
|
|
|
|
33
|
|
|
$this->getOutputInterface(), |
|
|
|
|
34
|
|
|
$this->getCommandBus() |
|
|
|
|
35
|
|
|
) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @test |
41
|
|
|
*/ |
42
|
|
|
public function itShouldNotExecuteHook() |
43
|
|
|
{ |
44
|
|
|
$this->shouldHandleQuery( |
45
|
|
|
new ConfigurationDataFinderQuery(), |
46
|
|
|
ConfigurationDataResponseStub::createCustom(false, false, false) |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
*/ |
55
|
|
|
public function itShouldThrowsExceptionFromOriginalScript() |
56
|
|
|
{ |
57
|
|
|
$this->expectException(InvalidPushException::class); |
58
|
|
|
|
59
|
|
|
$configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true); |
60
|
|
|
|
61
|
|
|
$this->shouldHandleQuery( |
62
|
|
|
new ConfigurationDataFinderQuery(), |
63
|
|
|
$configurationDataResponse |
64
|
|
|
); |
65
|
|
|
$this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK); |
66
|
|
|
$this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error'); |
67
|
|
|
$this->shouldWriteLnOutput( |
68
|
|
|
BadJobLogoResponse::paint($configurationDataResponse->getPrePush()->getErrorMessage()) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @test |
76
|
|
|
*/ |
77
|
|
|
public function itShouldWorksFine() |
78
|
|
|
{ |
79
|
|
|
$configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true); |
80
|
|
|
|
81
|
|
|
$this->shouldHandleQuery( |
82
|
|
|
new ConfigurationDataFinderQuery(), |
83
|
|
|
$configurationDataResponse |
84
|
|
|
); |
85
|
|
|
$this->shouldWriteLnOutput(PrePushTool::PRE_PUSH_HOOK); |
86
|
|
|
$this->shouldExecutePrePushOriginal($this->remote, $this->url, ''); |
87
|
|
|
$this->shouldHandleCommand( |
88
|
|
|
new PhpUnitToolCommand( |
89
|
|
|
$configurationDataResponse->getPrePush()->getPhpUnit()->isPhpunitRandomMode(), |
90
|
|
|
$configurationDataResponse->getPrePush()->getPhpUnit()->getPhpunitOptions(), |
91
|
|
|
$configurationDataResponse->getPrePush()->getErrorMessage() |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
$this->shouldHandleCommand( |
95
|
|
|
new StrictCoverageCommand( |
96
|
|
|
$configurationDataResponse->getPrePush()->getPhpUnitStrictCoverage()->getMinimum(), |
97
|
|
|
$configurationDataResponse->getPrePush()->getErrorMessage() |
98
|
|
|
) |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->shouldHandleCommand( |
102
|
|
|
new GuardCoverageCommand( |
103
|
|
|
$configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage() |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->shouldWriteLnOutput( |
108
|
|
|
GoodJobLogoResponse::paint($configurationDataResponse->getPrePush()->getRightMessage()) |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$this->prePushToolCommandHandler->handle(new PrePushToolCommand($this->remote, $this->url)); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.