|
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\Mockery as AppMockery; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class StagedFilesTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
use AppMockery; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Tests StagedFiles::replacement |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testCustomSeparator(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$repo = $this->createRepositoryMock(); |
|
27
|
|
|
$index = $this->createGitIndexOperator(['file1.php', 'file2.php', 'README.md']); |
|
28
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
29
|
|
|
|
|
30
|
|
|
$placeholder = new StagedFiles($repo); |
|
31
|
|
|
$command = $placeholder->replacement(['separated-by' => ', ']); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals('file1.php, file2.php, README.md', $command); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Tests StagedFiles::replacement |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testOfType(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$repo = $this->createRepositoryMock(); |
|
42
|
|
|
$index = $this->createGitIndexOperator(['file1.php', 'file2.php', 'README.md']); |
|
43
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
44
|
|
|
$index->expects($this->once())->method('getStagedFilesOfType')->willReturn(['file1.php', 'file2.php']); |
|
45
|
|
|
|
|
46
|
|
|
$placeholder = new StagedFiles($repo); |
|
47
|
|
|
$command = $placeholder->replacement(['of-type' => 'php']); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals('file1.php file2.php', $command); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|