|
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\Action\Cli\Command\Placeholder; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
|
15
|
|
|
use CaptainHook\App\Config\Mockery as ConfigMockery; |
|
16
|
|
|
use CaptainHook\App\Mockery as AppMockery; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class BranchFilesTest |
|
21
|
|
|
* |
|
22
|
|
|
* @package CaptainHook |
|
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
24
|
|
|
* @link https://github.com/captainhookphp/captainhook |
|
25
|
|
|
* @since Class available since Release 5.14.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class BranchFilesTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
use IOMockery; |
|
30
|
|
|
use AppMockery; |
|
31
|
|
|
use ConfigMockery; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Tests BranchFiles::replacement |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testFindStarByReflogWithCustomSeparator(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$io = $this->createIOMock(); |
|
39
|
|
|
$config = $this->createConfigMock(); |
|
40
|
|
|
$repo = $this->createRepositoryMock(); |
|
41
|
|
|
$info = $this->createGitInfoOperator(); |
|
42
|
|
|
$log = $this->createGitLogOperator(); |
|
43
|
|
|
|
|
44
|
|
|
$log->expects($this->once()) |
|
45
|
|
|
->method('getChangedFilesSince') |
|
46
|
|
|
->willReturn(['file1.php', 'file2.php', 'README.md']); |
|
47
|
|
|
$log->expects($this->once()) |
|
48
|
|
|
->method('getBranchRevFromRefLog') |
|
49
|
|
|
->willReturn('main'); |
|
50
|
|
|
$info->expects($this->once()) |
|
51
|
|
|
->method('getCurrentBranch') |
|
52
|
|
|
->willReturn('foo'); |
|
53
|
|
|
|
|
54
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
|
55
|
|
|
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info); |
|
56
|
|
|
|
|
57
|
|
|
$placeholder = new BranchFiles($io, $config, $repo); |
|
58
|
|
|
$replaced = $placeholder->replacement(['separated-by' => ',']); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertEquals('file1.php,file2.php,README.md', $replaced); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Tests BranchFiles::replacement |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testCantFindStartByReflog(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$io = $this->createIOMock(); |
|
69
|
|
|
$config = $this->createConfigMock(); |
|
70
|
|
|
$repo = $this->createRepositoryMock(); |
|
71
|
|
|
$info = $this->createGitInfoOperator(); |
|
72
|
|
|
$log = $this->createGitLogOperator(); |
|
73
|
|
|
|
|
74
|
|
|
$log->expects($this->once()) |
|
75
|
|
|
->method('getBranchRevFromRefLog') |
|
76
|
|
|
->willReturn(''); |
|
77
|
|
|
$info->expects($this->once()) |
|
78
|
|
|
->method('getCurrentBranch') |
|
79
|
|
|
->willReturn('foo'); |
|
80
|
|
|
|
|
81
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
|
82
|
|
|
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info); |
|
83
|
|
|
|
|
84
|
|
|
$placeholder = new BranchFiles($io, $config, $repo); |
|
85
|
|
|
$replaced = $placeholder->replacement([]); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals('', $replaced); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Tests BranchFiles::replacement |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testCompareToOfType(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$io = $this->createIOMock(); |
|
96
|
|
|
$config = $this->createConfigMock(); |
|
97
|
|
|
$repo = $this->createRepositoryMock(); |
|
98
|
|
|
$info = $this->createGitInfoOperator(); |
|
99
|
|
|
$log = $this->createGitLogOperator(); |
|
100
|
|
|
|
|
101
|
|
|
$log->expects($this->once()) |
|
102
|
|
|
->method('getChangedFilesSince') |
|
103
|
|
|
->willReturn(['file1.php', 'file2.php', 'README.md', 'foo.txt']); |
|
104
|
|
|
$info->expects($this->once()) |
|
105
|
|
|
->method('getCurrentBranch') |
|
106
|
|
|
->willReturn('foo'); |
|
107
|
|
|
|
|
108
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
|
109
|
|
|
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info); |
|
110
|
|
|
|
|
111
|
|
|
$placeholder = new BranchFiles($io, $config, $repo); |
|
112
|
|
|
$replaced = $placeholder->replacement(['compared-to' => 'main', 'of-type' => 'php']); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertEquals('file1.php file2.php', $replaced); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Tests BranchFiles::replacement |
|
119
|
|
|
*/ |
|
120
|
|
|
public function testFilterByDirectory(): void |
|
121
|
|
|
{ |
|
122
|
|
|
$io = $this->createIOMock(); |
|
123
|
|
|
$config = $this->createConfigMock(); |
|
124
|
|
|
$repo = $this->createRepositoryMock(); |
|
125
|
|
|
$info = $this->createGitInfoOperator(); |
|
126
|
|
|
$log = $this->createGitLogOperator(); |
|
127
|
|
|
|
|
128
|
|
|
$log->expects($this->once()) |
|
129
|
|
|
->method('getChangedFilesSince') |
|
130
|
|
|
->willReturn(['foo/file1.php', 'foo/file2.php', 'README.md']); |
|
131
|
|
|
$info->expects($this->once()) |
|
132
|
|
|
->method('getCurrentBranch') |
|
133
|
|
|
->willReturn('foo'); |
|
134
|
|
|
|
|
135
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
|
136
|
|
|
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info); |
|
137
|
|
|
|
|
138
|
|
|
$placeholder = new BranchFiles($io, $config, $repo); |
|
139
|
|
|
$replaced = $placeholder->replacement(['compared-to' => 'main', 'in-dir' => 'foo/']); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertEquals('foo/file1.php foo/file2.php', $replaced); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Tests BranchFiles::replacement |
|
146
|
|
|
*/ |
|
147
|
|
|
public function testReplaceWith(): void |
|
148
|
|
|
{ |
|
149
|
|
|
$io = $this->createIOMock(); |
|
150
|
|
|
$config = $this->createConfigMock(); |
|
151
|
|
|
$repo = $this->createRepositoryMock(); |
|
152
|
|
|
$info = $this->createGitInfoOperator(); |
|
153
|
|
|
$log = $this->createGitLogOperator(); |
|
154
|
|
|
|
|
155
|
|
|
$log->expects($this->once()) |
|
156
|
|
|
->method('getChangedFilesSince') |
|
157
|
|
|
->willReturn(['foo/file1.php', 'foo/file2.php', 'README.md']); |
|
158
|
|
|
$info->expects($this->once()) |
|
159
|
|
|
->method('getCurrentBranch') |
|
160
|
|
|
->willReturn('foo'); |
|
161
|
|
|
|
|
162
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
|
163
|
|
|
$repo->expects($this->atLeastOnce())->method('getInfoOperator')->willReturn($info); |
|
164
|
|
|
|
|
165
|
|
|
$placeholder = new BranchFiles($io, $config, $repo); |
|
166
|
|
|
$replaced = $placeholder->replacement(['compared-to' => 'main', 'replace' => 'foo/', 'with' => 'bar/']); |
|
167
|
|
|
|
|
168
|
|
|
$this->assertEquals('bar/file1.php bar/file2.php README.md', $replaced); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|