|
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
|
|
|
public function testCustomSeparator(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$io = $this->createIOMock(); |
|
36
|
|
|
$config = $this->createConfigMock(); |
|
37
|
|
|
$repo = $this->createRepositoryMock(); |
|
38
|
|
|
$index = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md']); |
|
39
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
|
40
|
|
|
|
|
41
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
|
42
|
|
|
$command = $placeholder->replacement(['separated-by' => ', ']); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals('file1.php, file2.php, README.md', $command); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testOfType(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$io = $this->createIOMock(); |
|
50
|
|
|
$config = $this->createConfigMock(); |
|
51
|
|
|
$repo = $this->createRepositoryMock(); |
|
52
|
|
|
$index = $this->createGitDiffOperator(['file1.php', 'file2.php', 'README.md']); |
|
53
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
|
54
|
|
|
|
|
55
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
|
56
|
|
|
$command = $placeholder->replacement(['of-type' => 'php']); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals('file1.php file2.php', $command); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testFilterByDirectory(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$io = $this->createIOMock(); |
|
64
|
|
|
$config = $this->createConfigMock(); |
|
65
|
|
|
$repo = $this->createRepositoryMock(); |
|
66
|
|
|
$index = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md']); |
|
67
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
|
68
|
|
|
|
|
69
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
|
70
|
|
|
$command = $placeholder->replacement(['in-dir' => 'foo/']); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals('foo/file1.php foo/file2.php', $command); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testReplaceWith(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$io = $this->createIOMock(); |
|
78
|
|
|
$config = $this->createConfigMock(); |
|
79
|
|
|
$repo = $this->createRepositoryMock(); |
|
80
|
|
|
$index = $this->createGitDiffOperator(['foo/file1.php', 'foo/file2.php', 'README.md']); |
|
81
|
|
|
$repo->expects($this->once())->method('getDiffOperator')->willReturn($index); |
|
82
|
|
|
|
|
83
|
|
|
$placeholder = new ChangedFiles($io, $config, $repo); |
|
84
|
|
|
$command = $placeholder->replacement(['replace' => 'foo/', 'with' => 'bar/']); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals('bar/file1.php bar/file2.php README.md', $command); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|