1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpUnit\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
6
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
7
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageCommand; |
8
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\CommandHandler\GuardCoverageToolCommandHandler; |
9
|
|
|
use PhpGitHooks\Module\PhpUnit\Service\GuardCoverageTool; |
10
|
|
|
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase; |
11
|
|
|
|
12
|
|
|
class GuardCoverageToolCommandHandlerTest extends PhpUnitUnitTestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var GuardCoverageToolCommandHandler |
16
|
|
|
*/ |
17
|
|
|
private $guardCoverageToolCommandHandler; |
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->guardCoverageToolCommandHandler = new GuardCoverageToolCommandHandler( |
22
|
|
|
new GuardCoverageTool( |
23
|
|
|
$this->getOutputInterface(), |
|
|
|
|
24
|
|
|
$this->getStrictCoverageProcessor(), |
|
|
|
|
25
|
|
|
$this->getGuardCoverageFileReader(), |
|
|
|
|
26
|
|
|
$this->getGuardCoverageFileWriter() |
|
|
|
|
27
|
|
|
) |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
*/ |
34
|
|
|
public function itShouldShowWarningMessage() |
35
|
|
|
{ |
36
|
|
|
$outputMessage = new PreCommitOutputWriter(GuardCoverageTool::CHECKING_MESSAGE); |
37
|
|
|
$currentCoverage = 60.00; |
38
|
|
|
$previousCoverage = 70.00; |
39
|
|
|
|
40
|
|
|
$this->shouldProcessStrictCoverage($currentCoverage); |
41
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
42
|
|
|
$this->shouldReadGuardCoverage($previousCoverage); |
43
|
|
|
$this->shouldWriteLnOutput( |
44
|
|
|
sprintf( |
45
|
|
|
"\n<bg=yellow;options=bold>%s Previous coverage %s, current coverage %s.</>", |
46
|
|
|
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT, |
47
|
|
|
$previousCoverage, |
48
|
|
|
$currentCoverage |
49
|
|
|
) |
50
|
|
|
); |
51
|
|
|
$this->shouldWriteGuardCoverage($currentCoverage); |
52
|
|
|
|
53
|
|
|
$this->guardCoverageToolCommandHandler->handle( |
54
|
|
|
new GuardCoverageCommand(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function itShouldWorksFine() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$outputMessage = new PreCommitOutputWriter(GuardCoverageTool::CHECKING_MESSAGE); |
64
|
|
|
$currentCoverage = 70.00; |
65
|
|
|
$previousCoverage = 60.00; |
66
|
|
|
|
67
|
|
|
$this->shouldProcessStrictCoverage($currentCoverage); |
68
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
69
|
|
|
$this->shouldReadGuardCoverage($previousCoverage); |
70
|
|
|
$this->shouldWriteLnOutput($this->buildStrictCoverageSuccessfulMessage($currentCoverage, $previousCoverage, |
71
|
|
|
$outputMessage->getSuccessfulMessage())); |
72
|
|
|
$this->shouldWriteGuardCoverage($currentCoverage); |
73
|
|
|
|
74
|
|
|
$this->guardCoverageToolCommandHandler->handle( |
75
|
|
|
new GuardCoverageCommand(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function buildStrictCoverageSuccessfulMessage($currentCoverage, $previousCoverage, $getSuccessfulMessage) |
80
|
|
|
{ |
81
|
|
|
return $getSuccessfulMessage . |
82
|
|
|
' <comment>[' . |
83
|
|
|
round($currentCoverage, 0) . |
84
|
|
|
'% >= ' . |
85
|
|
|
round($previousCoverage, 0) . |
86
|
|
|
'%]</comment>'; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.