forked from bruli/php-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuardCoverageToolHandlerTest.php
More file actions
90 lines (79 loc) · 3 KB
/
GuardCoverageToolHandlerTest.php
File metadata and controls
90 lines (79 loc) · 3 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
<?php
namespace PhpGitHooks\Module\PhpUnit\Tests\Behaviour;
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverage;
use PhpGitHooks\Module\PhpUnit\Contract\Command\GuardCoverageToolHandler;
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase;
class GuardCoverageToolHandlerTest extends PhpUnitUnitTestCase
{
/**
* @var GuardCoverageToolHandler
*/
private $guardCoverageToolCommandHandler;
protected function setUp(): void
{
$this->guardCoverageToolCommandHandler = new GuardCoverageToolHandler(
$this->getOutputInterface(),
$this->getStrictCoverageProcessor(),
$this->getGuardCoverageFileReader(),
$this->getGuardCoverageFileWriter()
);
}
/**
* @test
*/
public function itShouldShowWarningMessage()
{
$outputMessage = new PreCommitOutputWriter(GuardCoverageToolHandler::CHECKING_MESSAGE);
$currentCoverage = 60.00;
$previousCoverage = 70.00;
$this->shouldProcessStrictCoverage($currentCoverage);
$this->shouldWriteOutput($outputMessage->getMessage());
$this->shouldReadGuardCoverage($previousCoverage);
$this->shouldWriteLnOutput(
sprintf(
"\n<bg=yellow;options=bold>%s Previous coverage %s, current coverage %s.</>",
HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT,
$previousCoverage,
$currentCoverage
)
);
$this->shouldWriteGuardCoverage($currentCoverage);
$this->guardCoverageToolCommandHandler->handle(
new GuardCoverage(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT)
);
}
/**
* @test
*/
public function itShouldWorksFine()
{
$outputMessage = new PreCommitOutputWriter(GuardCoverageToolHandler::CHECKING_MESSAGE);
$currentCoverage = 70.00;
$previousCoverage = 60.00;
$this->shouldProcessStrictCoverage($currentCoverage);
$this->shouldWriteOutput($outputMessage->getMessage());
$this->shouldReadGuardCoverage($previousCoverage);
$this->shouldWriteLnOutput(
$this->buildStrictCoverageSuccessfulMessage(
$currentCoverage,
$previousCoverage,
$outputMessage->getSuccessfulMessage()
)
);
$this->shouldWriteGuardCoverage($currentCoverage);
$this->guardCoverageToolCommandHandler->handle(
new GuardCoverage(HookQuestions::PHPUNIT_GUARD_COVERAGE_MESSAGE_DEFAULT)
);
}
private function buildStrictCoverageSuccessfulMessage($currentCoverage, $previousCoverage, $getSuccessfulMessage)
{
return $getSuccessfulMessage .
' <comment>[' .
round($currentCoverage, 0) .
'% >= ' .
round($previousCoverage, 0) .
'%]</comment>';
}
}