|
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 sebastianfeldmann\CaptainHook\Runner; |
|
11
|
|
|
|
|
12
|
|
|
class HookTest extends BaseTestRunner |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Tests Installer::setHook |
|
16
|
|
|
* |
|
17
|
|
|
* @expectedException \Exception |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testSetHook() |
|
20
|
|
|
{ |
|
21
|
|
|
$io = $this->getIOMock(); |
|
22
|
|
|
$config = $this->getConfigMock(); |
|
23
|
|
|
$repo = $this->getRepositoryMock(); |
|
24
|
|
|
$runner = new Hook($io, $config, $repo); |
|
25
|
|
|
$runner->setHook('iDonExist'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Tests Installer::run |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testRunHookEnabled() |
|
32
|
|
|
{ |
|
33
|
|
|
$io = $this->getIOMock(); |
|
34
|
|
|
$config = $this->getConfigMock(); |
|
35
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
36
|
|
|
$actionConfig = $this->getActionConfigMock(); |
|
37
|
|
|
$repo = $this->getRepositoryMock(); |
|
38
|
|
|
$actionConfig->method('getType')->willReturn('cli'); |
|
39
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
|
40
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
|
41
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
42
|
|
|
$io->expects($this->exactly(3))->method('write'); |
|
43
|
|
|
|
|
44
|
|
|
$runner = new Hook($io, $config, $repo); |
|
45
|
|
|
$runner->setHook('pre-commit'); |
|
46
|
|
|
$runner->run(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Tests Installer::run |
|
51
|
|
|
*/ |
|
52
|
|
|
public function testRunHookEnabledDisabled() |
|
53
|
|
|
{ |
|
54
|
|
|
$io = $this->getIOMock(); |
|
55
|
|
|
$config = $this->getConfigMock(); |
|
56
|
|
|
$hookConfig = $this->getHookConfigMock(); |
|
57
|
|
|
$actionConfig = $this->getActionConfigMock(); |
|
58
|
|
|
$repo = $this->getRepositoryMock(); |
|
59
|
|
|
$actionConfig->method('getType')->willReturn('cli'); |
|
60
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(false); |
|
61
|
|
|
$config->expects($this->once())->method('getHookConfig')->willReturn($hookConfig); |
|
62
|
|
|
$io->expects($this->once())->method('write'); |
|
63
|
|
|
|
|
64
|
|
|
$runner = new Hook($io, $config, $repo); |
|
65
|
|
|
$runner->setHook('pre-commit'); |
|
66
|
|
|
$runner->run(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Tests Hook::getActionRunner |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testGetRunner() |
|
73
|
|
|
{ |
|
74
|
|
|
$io = $this->getIOMock(); |
|
75
|
|
|
$config = $this->getConfigMock(); |
|
76
|
|
|
$repo = $this->getRepositoryMock(); |
|
77
|
|
|
|
|
78
|
|
|
$hook = new Hook($io, $config, $repo); |
|
79
|
|
|
$php = $hook->getActionRunner('php'); |
|
80
|
|
|
$cli = $hook->getActionRunner('cli'); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertTrue(is_a($php, '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\PHP')); |
|
83
|
|
|
$this->assertTrue(is_a($cli, '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\Cli')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Tests Hook::getActionRunner |
|
88
|
|
|
* |
|
89
|
|
|
* @expectedException \Exception |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testGetRunnerFailure() |
|
92
|
|
|
{ |
|
93
|
|
|
$io = $this->getIOMock(); |
|
94
|
|
|
$config = $this->getConfigMock(); |
|
95
|
|
|
$repo = $this->getRepositoryMock(); |
|
96
|
|
|
|
|
97
|
|
|
$hook = new Hook($io, $config, $repo); |
|
98
|
|
|
$hook->getActionRunner('foo'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|