1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\PhpUnit\Tests\Behaviour; |
4
|
|
|
|
5
|
|
|
use PhpGitHooks\Module\Configuration\Service\HookQuestions; |
6
|
|
|
use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
7
|
|
|
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
8
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitTool; |
9
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Command\PhpUnitToolHandler; |
10
|
|
|
use PhpGitHooks\Module\PhpUnit\Contract\Exception\PhpUnitViolationException; |
11
|
|
|
use PhpGitHooks\Module\PhpUnit\Tests\Infrastructure\PhpUnitUnitTestCase; |
12
|
|
|
|
13
|
|
|
class PhpUnitToolHandlerTest extends PhpUnitUnitTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var PhpUnitToolHandler |
17
|
|
|
*/ |
18
|
|
|
private $phpUnitToolCommandHandler; |
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->phpUnitToolCommandHandler = new PhpUnitToolHandler( |
23
|
|
|
$this->getOutputInterface(), |
24
|
|
|
$this->getPhpUnitProcessor(), |
|
|
|
|
25
|
|
|
$this->getPhpUnitProcessor() |
|
|
|
|
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
*/ |
32
|
|
|
public function itShouldThrowsException() |
33
|
|
|
{ |
34
|
|
|
$this->expectException(PhpUnitViolationException::class); |
35
|
|
|
|
36
|
|
|
$options = '--testsuite default'; |
37
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
38
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpUnitToolHandler::EXECUTING_MESSAGE); |
39
|
|
|
|
40
|
|
|
$this->shouldWriteLnOutput($outputMessage->getMessage()); |
41
|
|
|
$this->shouldProcessPhpUnit($options, false); |
42
|
|
|
$this->shouldWriteLnOutput(BadJobLogoResponse::paint($errorMessage)); |
43
|
|
|
|
44
|
|
|
$this->phpUnitToolCommandHandler->handle( |
45
|
|
|
new PhpUnitTool( |
46
|
|
|
true, |
47
|
|
|
$options, |
48
|
|
|
$errorMessage |
49
|
|
|
) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function itShouldExecuteAndWorksFine() |
57
|
|
|
{ |
58
|
|
|
$options = '--testsuite default'; |
59
|
|
|
$errorMessage = HookQuestions::PRE_COMMIT_ERROR_MESSAGE_DEFAULT; |
60
|
|
|
$outputMessage = new PreCommitOutputWriter(PhpUnitToolHandler::EXECUTING_MESSAGE); |
61
|
|
|
|
62
|
|
|
$this->shouldWriteLnOutput($outputMessage->getMessage()); |
63
|
|
|
$this->shouldProcessPhpUnit($options, true); |
64
|
|
|
|
65
|
|
|
$this->phpUnitToolCommandHandler->handle( |
66
|
|
|
new PhpUnitTool( |
67
|
|
|
true, |
68
|
|
|
$options, |
69
|
|
|
$errorMessage |
70
|
|
|
) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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.