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\Hook\Condition\Branch; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use CaptainHook\App\Mockery as AppMockery; |
16
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
17
|
|
|
|
18
|
|
|
class FilesTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use AppMockery; |
21
|
|
|
use IOMockery; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tests Files::isTrue |
25
|
|
|
*/ |
26
|
|
|
public function testBranchFilesWithReflog(): void |
27
|
|
|
{ |
28
|
|
|
$io = $this->createIOMock(); |
29
|
|
|
$repo = $this->createRepositoryMock(); |
30
|
|
|
$info = $this->createGitInfoOperator(); |
31
|
|
|
$log = $this->createGitLogOperator(); |
32
|
|
|
|
33
|
|
|
$log->expects($this->once()) |
34
|
|
|
->method('getChangedFilesSince') |
35
|
|
|
->willReturn(['file1.php', 'file2.php', 'README.md']); |
36
|
|
|
$log->expects($this->once()) |
37
|
|
|
->method('getBranchRevFromRefLog') |
38
|
|
|
->willReturn('main'); |
39
|
|
|
$info->expects($this->once()) |
40
|
|
|
->method('getCurrentBranch') |
41
|
|
|
->willReturn('foo'); |
42
|
|
|
|
43
|
|
|
$repo->expects($this->once())->method('getInfoOperator')->willReturn($info); |
44
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
45
|
|
|
|
46
|
|
|
$files = new Files(['of-type' => 'php']); |
47
|
|
|
$this->assertTrue($files->isTrue($io, $repo)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Tests Files::isTrue |
52
|
|
|
*/ |
53
|
|
|
public function testBranchFilesWithEmptyReflog(): void |
54
|
|
|
{ |
55
|
|
|
$io = $this->createIOMock(); |
56
|
|
|
$repo = $this->createRepositoryMock(); |
57
|
|
|
$info = $this->createGitInfoOperator(); |
58
|
|
|
$log = $this->createGitLogOperator(); |
59
|
|
|
|
60
|
|
|
$log->expects($this->once()) |
61
|
|
|
->method('getBranchRevFromRefLog') |
62
|
|
|
->willReturn(''); |
63
|
|
|
$info->expects($this->once()) |
64
|
|
|
->method('getCurrentBranch') |
65
|
|
|
->willReturn('foo'); |
66
|
|
|
|
67
|
|
|
$repo->expects($this->once())->method('getInfoOperator')->willReturn($info); |
68
|
|
|
$repo->expects($this->atLeastOnce())->method('getLogOperator')->willReturn($log); |
69
|
|
|
|
70
|
|
|
$files = new Files(['of-type' => 'php']); |
71
|
|
|
$this->assertFalse($files->isTrue($io, $repo)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Tests Files::isTrue |
76
|
|
|
*/ |
77
|
|
|
public function testComparedToInDirectory(): void |
78
|
|
|
{ |
79
|
|
|
$io = $this->createIOMock(); |
80
|
|
|
$repo = $this->createRepositoryMock(); |
81
|
|
|
$info = $this->createGitInfoOperator(); |
82
|
|
|
$log = $this->createGitLogOperator(); |
83
|
|
|
|
84
|
|
|
$log->expects($this->once()) |
85
|
|
|
->method('getChangedFilesSince') |
86
|
|
|
->willReturn(['foo/file1.php', 'bar/file2.php', 'README.md']); |
87
|
|
|
$info->expects($this->once()) |
88
|
|
|
->method('getCurrentBranch') |
89
|
|
|
->willReturn('foo'); |
90
|
|
|
|
91
|
|
|
$repo->expects($this->once())->method('getInfoOperator')->willReturn($info); |
92
|
|
|
$repo->expects($this->once())->method('getLogOperator')->willReturn($log); |
93
|
|
|
|
94
|
|
|
$files = new Files(['compared-to' => 'main', 'in-dir' => 'foo/']); |
95
|
|
|
$this->assertTrue($files->isTrue($io, $repo)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|