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