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