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 ChangedFilesTest |
21
|
|
|
* |
22
|
|
|
* @package CaptainHook |
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
24
|
|
|
* @link https://github.com/captainhook-git/captainhook |
25
|
|
|
* @since Class available since Release 5.14.0 |
26
|
|
|
*/ |
27
|
|
|
class ChangedFilesTest extends TestCase |
28
|
|
|
{ |
29
|
|
|
use IOMockery; |
30
|
|
|
use AppMockery; |
31
|
|
|
use ConfigMockery; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tests ChangedFiles::replacement |
35
|
|
|
*/ |
36
|
|
|
public function testCustomSeparator(): void |
37
|
|
|
{ |
38
|
|
|
$io = $this->createIOMock(); |
39
|
|
|
$config = $this->createConfigMock(); |
40
|
|
|
$repo = $this->createRepositoryMock(); |
41
|
|
|
$index = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md']); |
42
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
43
|
|
|
|
44
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
45
|
|
|
$command = $placeholder->replacement(['separated-by' => ', ']); |
46
|
|
|
|
47
|
|
|
$this->assertEquals('file1.php, file2.php, README.md', $command); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Tests ChangedFiles::replacement |
52
|
|
|
*/ |
53
|
|
|
public function testOfType(): void |
54
|
|
|
{ |
55
|
|
|
$io = $this->createIOMock(); |
56
|
|
|
$config = $this->createConfigMock(); |
57
|
|
|
$repo = $this->createRepositoryMock(); |
58
|
|
|
$index = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md']); |
59
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
60
|
|
|
|
61
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
62
|
|
|
$command = $placeholder->replacement(['of-type' => 'php']); |
63
|
|
|
|
64
|
|
|
$this->assertEquals('file1.php file2.php', $command); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests ChangedFiles::replacement |
69
|
|
|
*/ |
70
|
|
|
public function testFilterByDirectory(): void |
71
|
|
|
{ |
72
|
|
|
$io = $this->createIOMock(); |
73
|
|
|
$config = $this->createConfigMock(); |
74
|
|
|
$repo = $this->createRepositoryMock(); |
75
|
|
|
$index = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md']); |
76
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
77
|
|
|
|
78
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
79
|
|
|
$command = $placeholder->replacement(['in-dir' => 'foo/']); |
80
|
|
|
|
81
|
|
|
$this->assertEquals('foo/file1.php foo/file2.php', $command); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Tests ChangedFiles::replacement |
86
|
|
|
*/ |
87
|
|
|
public function testReplaceWith(): void |
88
|
|
|
{ |
89
|
|
|
$io = $this->createIOMock(); |
90
|
|
|
$config = $this->createConfigMock(); |
91
|
|
|
$repo = $this->createRepositoryMock(); |
92
|
|
|
$index = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md']); |
93
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
94
|
|
|
|
95
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
96
|
|
|
$command = $placeholder->replacement(['replace' => 'foo/', 'with' => 'bar/']); |
97
|
|
|
|
98
|
|
|
$this->assertEquals('bar/file1.php bar/file2.php README.md', $command); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|