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\Mockery as CHMockery; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class PostRewriteTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use ConfigMockery; |
22
|
|
|
use IOMockery; |
23
|
|
|
use CHMockery; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Tests PrePush::run |
27
|
|
|
* |
28
|
|
|
* @throws \Exception |
29
|
|
|
*/ |
30
|
|
|
public function testRunHookEnabled(): void |
31
|
|
|
{ |
32
|
|
|
$io = $this->createIOMock(); |
33
|
|
|
$config = $this->createConfigMock(); |
34
|
|
|
$repo = $this->createRepositoryMock(); |
35
|
|
|
$hookConfig = $this->createHookConfigMock(); |
36
|
|
|
|
37
|
|
|
// configure the actually called hook |
38
|
|
|
$actionConfig = $this->createActionConfigMock(); |
39
|
|
|
$hookConfig->expects($this->atLeastOnce())->method('getName')->willReturn('post-rewrite'); |
40
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
41
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
42
|
|
|
|
43
|
|
|
// configure the virtual hook |
44
|
|
|
$vHookConfig = $this->createHookConfigMock(); |
45
|
|
|
$vActionConfig = $this->createActionConfigMock(); |
46
|
|
|
$vHookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
47
|
|
|
$vHookConfig->expects($this->once())->method('getActions')->willReturn([$vActionConfig]); |
48
|
|
|
|
49
|
|
|
// the config wll return the actually called config and then the virtual hook config |
50
|
|
|
$config->expects($this->exactly(2)) |
51
|
|
|
->method('getHookConfig') |
52
|
|
|
->willReturnOnConsecutiveCalls($hookConfig, $vHookConfig); |
53
|
|
|
|
54
|
|
|
$io->expects($this->atLeast(1))->method('write'); |
55
|
|
|
|
56
|
|
|
$runner = new PostRewrite($io, $config, $repo); |
57
|
|
|
$runner->run(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Tests PrePush::run |
62
|
|
|
* |
63
|
|
|
* @throws \Exception |
64
|
|
|
*/ |
65
|
|
|
public function testRunVirtualHookDisabled(): void |
66
|
|
|
{ |
67
|
|
|
$io = $this->createIOMock(); |
68
|
|
|
$config = $this->createConfigMock(); |
69
|
|
|
$repo = $this->createRepositoryMock(); |
70
|
|
|
$hookConfig = $this->createHookConfigMock(); |
71
|
|
|
|
72
|
|
|
// configure the actually called hook |
73
|
|
|
$actionConfig = $this->createActionConfigMock(); |
74
|
|
|
$hookConfig->expects($this->atLeastOnce())->method('getName')->willReturn('post-rewrite'); |
75
|
|
|
$hookConfig->expects($this->once())->method('isEnabled')->willReturn(true); |
76
|
|
|
$hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]); |
77
|
|
|
|
78
|
|
|
// configure the virtual hook |
79
|
|
|
$vHookConfig = $this->createHookConfigMock(); |
80
|
|
|
$vHookConfig->expects($this->once())->method('isEnabled')->willReturn(false); |
81
|
|
|
|
82
|
|
|
// the config wll return the actually called config and then the virtual hook config |
83
|
|
|
$config->expects($this->exactly(2)) |
84
|
|
|
->method('getHookConfig') |
85
|
|
|
->willReturnOnConsecutiveCalls($hookConfig, $vHookConfig); |
86
|
|
|
|
87
|
|
|
$io->expects($this->atLeast(1))->method('write'); |
88
|
|
|
|
89
|
|
|
$runner = new PostRewrite($io, $config, $repo); |
90
|
|
|
$runner->run(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|