forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrePushToolHandlerTest.php
More file actions
110 lines (95 loc) · 3.86 KB
/
PrePushToolHandlerTest.php
File metadata and controls
110 lines (95 loc) · 3.86 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
<?php
namespace PhpGitHooks\Module\Git\Tests\Behaviour;
use PhpGitHooks\Module\Configuration\Contract\Query\ConfigurationDataFinder;
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub;
use PhpGitHooks\Module\Git\Contract\Command\PrePushTool;
use PhpGitHooks\Module\Git\Contract\Command\PrePushToolHandler;
use PhpGitHooks\Module\Git\Contract\Exception\InvalidPushException;
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse;
use PhpGitHooks\Module\Git\Contract\Response\GoodJobLogoResponse;
use PhpGitHooks\Module\Git\Tests\Infrastructure\GitUnitTestCase;
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverage;
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool;
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverage;
class PrePushToolHandlerTest extends GitUnitTestCase
{
private $remote = 'origin';
private $url = 'git@github.com';
/**
* @var PrePushToolHandler
*/
private $prePushToolCommandHandler;
protected function setUp(): void
{
$this->prePushToolCommandHandler = new PrePushToolHandler(
$this->getQueryBus(),
$this->getPrePushOriginalExecutor(),
$this->getOutputInterface(),
$this->getCommandBus()
);
}
/**
* @test
*/
public function itShouldNotExecuteHook()
{
$this->shouldHandleQuery(
new ConfigurationDataFinder(),
ConfigurationDataResponseStub::createCustom(false, false, false)
);
$this->prePushToolCommandHandler->handle(new PrePushTool($this->remote, $this->url));
}
/**
* @test
*/
public function itShouldThrowsExceptionFromOriginalScript()
{
$this->expectException(InvalidPushException::class);
$configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
$this->shouldHandleQuery(
new ConfigurationDataFinder(),
$configurationDataResponse
);
$this->shouldWriteLnOutput(PrePushToolHandler::PRE_PUSH_HOOK);
$this->shouldExecutePrePushOriginal($this->remote, $this->url, 'error');
$this->shouldWriteLnOutput(
BadJobLogoResponse::paint($configurationDataResponse->getPrePush()->getErrorMessage())
);
$this->prePushToolCommandHandler->handle(new PrePushTool($this->remote, $this->url));
}
/**
* @test
*/
public function itShouldWorksFine()
{
$configurationDataResponse = ConfigurationDataResponseStub::createCustom(false, false, true);
$this->shouldHandleQuery(
new ConfigurationDataFinder(),
$configurationDataResponse
);
$this->shouldWriteLnOutput(PrePushToolHandler::PRE_PUSH_HOOK);
$this->shouldExecutePrePushOriginal($this->remote, $this->url, '');
$this->shouldHandleCommand(
new PhpUnitTool(
$configurationDataResponse->getPrePush()->getPhpUnit()->isPhpunitRandomMode(),
$configurationDataResponse->getPrePush()->getPhpUnit()->getPhpunitOptions(),
$configurationDataResponse->getPrePush()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new StrictCoverage(
$configurationDataResponse->getPrePush()->getPhpUnitStrictCoverage()->getMinimum(),
$configurationDataResponse->getPrePush()->getErrorMessage()
)
);
$this->shouldHandleCommand(
new GuardCoverage(
$configurationDataResponse->getPreCommit()->getPhpUnitGuardCoverage()->getWarningMessage()
)
);
$this->shouldWriteLnOutput(
GoodJobLogoResponse::paint($configurationDataResponse->getPrePush()->getRightMessage())
);
$this->prePushToolCommandHandler->handle(new PrePushTool($this->remote, $this->url));
}
}