1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of CaptainHook |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Runner\Hook; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Config\Mockery as ConfigMockery; |
15
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
16
|
|
|
use CaptainHook\App\Git\DummyRepo; |
17
|
|
|
use CaptainHook\App\Mockery as CHMockery; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
class PrePushTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
use ConfigMockery; |
23
|
|
|
use IOMockery; |
24
|
|
|
use CHMockery; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Tests PrePush::run |
28
|
|
|
* |
29
|
|
|
* @throws \Exception |
30
|
|
|
*/ |
31
|
|
|
public function testRunHookEnabled(): void |
32
|
|
|
{ |
33
|
|
|
$dummy = new DummyRepo(['hooks' => ['pre-push' => '# hook script']]); |
34
|
|
|
$repo = $this->createRepositoryMock($dummy->getRoot()); |
35
|
|
|
$repo->method('getHooksDir')->willReturn($dummy->getHookDir()); |
36
|
|
|
|
37
|
|
|
$io = $this->createIOMock(); |
38
|
|
|
$config = $this->createConfigMock(); |
39
|
|
|
$hookConfig = $this->createHookConfigMock(); |
40
|
|
|
$actionConfig = $this->createActionConfigMock(); |
41
|
|
|
$hookConfig->method('isEnabled')->willReturn(true); |
42
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
43
|
|
|
$config->expects($this->once())->method('getHookConfigToExecute')->willReturn($hookConfig); |
44
|
|
|
$config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(true); |
45
|
|
|
$io->expects($this->atLeast(1))->method('write'); |
46
|
|
|
|
47
|
|
|
$runner = new PrePush($io, $config, $repo); |
48
|
|
|
$runner->run(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Tests PrePush::run |
53
|
|
|
* |
54
|
|
|
* @throws \Exception |
55
|
|
|
*/ |
56
|
|
|
public function testRunHookEnabledNoActions(): void |
57
|
|
|
{ |
58
|
|
|
$dummy = new DummyRepo(['hooks' => ['pre-push' => '# hook script']]); |
59
|
|
|
$repo = $this->createRepositoryMock($dummy->getRoot()); |
60
|
|
|
$repo->method('getHooksDir')->willReturn($dummy->getHookDir()); |
61
|
|
|
|
62
|
|
|
$io = $this->createIOMock(); |
63
|
|
|
$config = $this->createConfigMock(); |
64
|
|
|
$hookConfig = $this->createHookConfigMock(); |
65
|
|
|
$hookConfig->method('isEnabled')->willReturn(true); |
66
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([]); |
67
|
|
|
$config->expects($this->once())->method('getHookConfigToExecute')->willReturn($hookConfig); |
68
|
|
|
$config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(true); |
69
|
|
|
$io->expects($this->atLeast(1))->method('write'); |
70
|
|
|
|
71
|
|
|
$runner = new PrePush($io, $config, $repo); |
72
|
|
|
$runner->run(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Tests PrePush::run |
77
|
|
|
* |
78
|
|
|
* @throws \Exception |
79
|
|
|
*/ |
80
|
|
|
public function testRunHookDisabled(): void |
81
|
|
|
{ |
82
|
|
|
$io = $this->createIOMock(); |
83
|
|
|
$config = $this->createConfigMock(); |
84
|
|
|
$repo = $this->createRepositoryMock(); |
85
|
|
|
$config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(false); |
86
|
|
|
$io->expects($this->atLeast(1))->method('write'); |
87
|
|
|
|
88
|
|
|
$runner = new PrePush($io, $config, $repo); |
89
|
|
|
$runner->run(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|