|
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\FileStaged; |
|
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 ThatIsTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
use AppMockery; |
|
21
|
|
|
use IOMockery; |
|
22
|
|
|
|
|
23
|
|
|
public function testPreCommitRestriction(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->assertTrue(ThatIs::getRestriction()->isApplicableFor('pre-commit')); |
|
26
|
|
|
$this->assertFalse(ThatIs::getRestriction()->isApplicableFor('pre-push')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testStagedTrueType(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$io = $this->createIOMock(); |
|
32
|
|
|
$repo = $this->createRepositoryMock(); |
|
33
|
|
|
$index = $this->createGitIndexOperator(['foo.php', 'bar.php']); |
|
34
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
35
|
|
|
|
|
36
|
|
|
$thatIs = new ThatIs(['ofType' => 'php']); |
|
37
|
|
|
$this->assertTrue($thatIs->isTrue($io, $repo)); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testStagedTrueMultipleType(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$io = $this->createIOMock(); |
|
43
|
|
|
$repo = $this->createRepositoryMock(); |
|
44
|
|
|
$index = $this->createGitIndexOperator(['foo.php', 'bar.php']); |
|
45
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
46
|
|
|
|
|
47
|
|
|
$thatIs = new ThatIs(['ofType' => ['php', 'js']]); |
|
48
|
|
|
$this->assertTrue($thatIs->isTrue($io, $repo)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testStagedFalseMultipleType(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$io = $this->createIOMock(); |
|
54
|
|
|
$repo = $this->createRepositoryMock(); |
|
55
|
|
|
$index = $this->createGitIndexOperator(['foo.php', 'bar.php']); |
|
56
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
57
|
|
|
|
|
58
|
|
|
$thatIs = new ThatIs(['ofType' => ['ts', 'js']]); |
|
59
|
|
|
$this->assertFalse($thatIs->isTrue($io, $repo)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testStagedTrueDirectory(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$io = $this->createIOMock(); |
|
65
|
|
|
$repo = $this->createRepositoryMock(); |
|
66
|
|
|
$index = $this->createGitIndexOperator(['foo/foo.php', 'bar/bar.js', 'fiz/baz.txt']); |
|
67
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
68
|
|
|
|
|
69
|
|
|
$thatIs = new ThatIs(['inDirectory' => 'bar/']); |
|
70
|
|
|
$this->assertTrue($thatIs->isTrue($io, $repo)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testStagedFalsePartialDirectory(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$io = $this->createIOMock(); |
|
76
|
|
|
$repo = $this->createRepositoryMock(); |
|
77
|
|
|
$index = $this->createGitIndexOperator(['foo/foo.php', 'foo/bar/bar.js', 'fiz/baz.txt']); |
|
78
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
79
|
|
|
|
|
80
|
|
|
$thatIs = new ThatIs(['inDirectory' => 'bar/']); |
|
81
|
|
|
$this->assertFalse($thatIs->isTrue($io, $repo)); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testStagedTrueMultipleDirectory(): void |
|
85
|
|
|
{ |
|
86
|
|
|
$io = $this->createIOMock(); |
|
87
|
|
|
$repo = $this->createRepositoryMock(); |
|
88
|
|
|
$index = $this->createGitIndexOperator(['foo/foo.php', 'bar/bar.js', 'fiz/baz.txt']); |
|
89
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
90
|
|
|
|
|
91
|
|
|
$thatIs = new ThatIs(['inDirectory' => ['bar/', 'baz/']]); |
|
92
|
|
|
$this->assertTrue($thatIs->isTrue($io, $repo)); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function testStagedFalseMultipleDirectory(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$io = $this->createIOMock(); |
|
98
|
|
|
$repo = $this->createRepositoryMock(); |
|
99
|
|
|
$index = $this->createGitIndexOperator(['foo/foo.php', 'bar/bar.js', 'fiz/baz.txt']); |
|
100
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
101
|
|
|
|
|
102
|
|
|
$thatIs = new ThatIs(['inDirectory' => ['foobar/', 'baz/'], 'diffFilter' => ['A', 'C']]); |
|
103
|
|
|
$this->assertFalse($thatIs->isTrue($io, $repo)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testStagedFalseDirectoryAndType(): void |
|
107
|
|
|
{ |
|
108
|
|
|
$io = $this->createIOMock(); |
|
109
|
|
|
$repo = $this->createRepositoryMock(); |
|
110
|
|
|
$index = $this->createGitIndexOperator(['foo/foo.php', 'bar/bar.js']); |
|
111
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
112
|
|
|
|
|
113
|
|
|
$thatIs = new ThatIs(['inDirectory' => 'bar/', 'ofType' => 'php']); |
|
114
|
|
|
$this->assertFalse($thatIs->isTrue($io, $repo)); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function testStagedFalse(): void |
|
118
|
|
|
{ |
|
119
|
|
|
$io = $this->createIOMock(); |
|
120
|
|
|
$repo = $this->createRepositoryMock(); |
|
121
|
|
|
$index = $this->createGitIndexOperator(['foo.php']); |
|
122
|
|
|
$repo->expects($this->once())->method('getIndexOperator')->willReturn($index); |
|
123
|
|
|
|
|
124
|
|
|
$thatIs = new ThatIs(['ofType' => 'js']); |
|
125
|
|
|
$this->assertFalse($thatIs->isTrue($io, $repo)); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|