1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpUnit\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigArrayDataStub; |
6
|
|
|
use PhpGitHooks\Module\Configuration\Tests\Stub\MinimumStrictCoverageStub; |
7
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
8
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
9
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverage; |
10
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\StrictCoverageToolHandler; |
11
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Exception\InvalidStrictCoverageException; |
12
|
|
|
use PhpGitHooks\Module\PhpUnit\Service\StrictCoverageTool; |
13
|
|
|
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase; |
14
|
|
|
|
15
|
|
|
class StrictCoverageToolHandlerTest extends PhpUnitUnitTestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $errorMessage; |
21
|
|
|
/** |
22
|
|
|
* @var StrictCoverageToolHandler |
23
|
|
|
*/ |
24
|
|
|
private $strictCoverageToolCommandHandler; |
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
$this->errorMessage = ConfigArrayDataStub::ERROR_MESSAGE; |
29
|
|
|
$this->strictCoverageToolCommandHandler = new StrictCoverageToolHandler( |
30
|
|
|
$this->getOutputInterface(), |
31
|
|
|
new StrictCoverageTool( |
32
|
|
|
$this->getStrictCoverageProcessor(), |
|
|
|
|
33
|
|
|
$this->getOutputInterface() |
34
|
|
|
) |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
|
|
public function itShouldThrowsException() |
42
|
|
|
{ |
43
|
|
|
$this->expectException(InvalidStrictCoverageException::class); |
44
|
|
|
|
45
|
|
|
$minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00); |
46
|
|
|
$outputMessage = new PreCommitOutputWriter(StrictCoverageToolHandler::EXECUTE_MESSAGE); |
47
|
|
|
|
48
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
49
|
|
|
$this->shouldProcessStrictCoverage(0.00); |
50
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); |
51
|
|
|
|
52
|
|
|
$command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage); |
53
|
|
|
$this->strictCoverageToolCommandHandler->handle($command); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function itShouldWorksFine() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$minimumStrictCoverage = MinimumStrictCoverageStub::create(90.00); |
62
|
|
|
$outputMessage = new PreCommitOutputWriter(StrictCoverageToolHandler::EXECUTE_MESSAGE); |
63
|
|
|
|
64
|
|
|
$coverage = 91.00; |
65
|
|
|
|
66
|
|
|
$this->shouldWriteOutput($outputMessage->getMessage()); |
67
|
|
|
$this->shouldProcessStrictCoverage($coverage); |
68
|
|
|
$this->shouldWriteLnOutput( |
69
|
|
|
$this->buildStrictCoverageSuccessfulMessage( |
70
|
|
|
$coverage, |
71
|
|
|
$outputMessage->getSuccessfulMessage() |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$command = new StrictCoverage($minimumStrictCoverage->value(), $this->errorMessage); |
76
|
|
|
$this->strictCoverageToolCommandHandler->handle($command); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function buildStrictCoverageSuccessfulMessage($coverage, $getSuccessfulMessage) |
80
|
|
|
{ |
81
|
|
|
return $getSuccessfulMessage . ' <comment>[' . round($coverage, 0) . '%]</comment>'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.