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