|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of CaptainHook. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace CaptainHook\App\Runner\Hook; |
|
11
|
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
|
13
|
|
|
use CaptainHook\App\Runner\BaseTestRunner; |
|
14
|
|
|
|
|
15
|
|
|
class CommitMsgTest extends BaseTestRunner |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Tests CommitMsg::run |
|
19
|
|
|
*/ |
|
20
|
|
|
public function testRunHookEnabled(): void |
|
21
|
|
|
{ |
|
22
|
|
|
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { |
|
23
|
|
|
$this->markTestSkipped('not tested on windows'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$io = $this->getIOMock(); |
|
27
|
|
|
$config = $this->getConfigMock(); |
|
28
|
|
|
$configOp = $this->createMock(\SebastianFeldmann\Git\Operator\Config::class); |
|
29
|
|
|
$configOp->expects($this->once())->method('getSafely')->willReturn('#'); |
|
30
|
|
|
|
|
31
|
|
|
$repo = $this->getRepositoryMock(); |
|
32
|
|
|
$repo->expects($this->once())->method('getConfigOperator')->willReturn($configOp); |
|
33
|
|
|
|
|
34
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
35
|
|
|
$actionConfig = $this->getActionConfigMock(); |
|
36
|
|
|
$actionConfig->method('getAction')->willReturn(CH_PATH_FILES . '/bin/success'); |
|
37
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
|
38
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
|
39
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
40
|
|
|
$io->expects($this->exactly(3))->method('write'); |
|
41
|
|
|
$io->expects($this->once())->method('getArgument')->willReturn(CH_PATH_FILES . '/git/message/valid.txt'); |
|
42
|
|
|
|
|
43
|
|
|
$runner = new CommitMsg($io, $config, $repo); |
|
44
|
|
|
$runner->run(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Tests CommitMsg::run |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testRunWithoutCommitMsgFile(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->expectException(\Exception::class); |
|
53
|
|
|
|
|
54
|
|
|
$io = $this->getIOMock(); |
|
55
|
|
|
$config = $this->getConfigMock(); |
|
56
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
57
|
|
|
$repo = $this->getRepositoryMock(); |
|
58
|
|
|
$actionConfig = $this->getActionConfigMock(); |
|
59
|
|
|
$actionConfig->method('getAction')->willReturn(CH_PATH_FILES . '/bin/success'); |
|
60
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
|
61
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
|
62
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
63
|
|
|
$io->expects($this->once())->method('getArgument')->willReturn(''); |
|
64
|
|
|
|
|
65
|
|
|
$runner = new CommitMsg($io, $config, $repo); |
|
66
|
|
|
$runner->run(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|