|
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 CaptainHook\App\Console\IO\Mockery as IOMockery; |
|
15
|
|
|
use CaptainHook\App\Mockery as CHMockery; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class AnyTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
use IOMockery; |
|
21
|
|
|
use CHMockery; |
|
22
|
|
|
|
|
23
|
|
|
public function testIsTrue(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$io = $this->createIOMock(); |
|
26
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']); |
|
27
|
|
|
$repository = $this->createRepositoryMock(''); |
|
28
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
|
29
|
|
|
|
|
30
|
|
|
$fileStaged = new Any(['foo.php', 'bar.php']); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertTrue($fileStaged->isTrue($io, $repository)); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testIsTrueWithStringFilter(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$io = $this->createIOMock(); |
|
38
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']); |
|
39
|
|
|
$repository = $this->createRepositoryMock(''); |
|
40
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
|
41
|
|
|
|
|
42
|
|
|
$fileStaged = new Any(['foo.php', 'bar.php'], 'ARC'); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertTrue($fileStaged->isTrue($io, $repository)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testWithWildcardIsTrue(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$io = $this->createIOMock(); |
|
50
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']); |
|
51
|
|
|
$repository = $this->createRepositoryMock(''); |
|
52
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
|
53
|
|
|
|
|
54
|
|
|
$fileStaged = new Any(['foo.*', 'bar.php']); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertTrue($fileStaged->isTrue($io, $repository)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testIsFalse(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$io = $this->createIOMock(); |
|
62
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php']); |
|
63
|
|
|
$repository = $this->createRepositoryMock(''); |
|
64
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
|
65
|
|
|
|
|
66
|
|
|
$fileStaged = new Any(['foo.php', 'bar.php']); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertFalse($fileStaged->isTrue($io, $repository)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testWithWildcardIsFalse(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$io = $this->createIOMock(); |
|
74
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php']); |
|
75
|
|
|
$repository = $this->createRepositoryMock(''); |
|
76
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
|
77
|
|
|
|
|
78
|
|
|
$fileStaged = new Any(['fo?.php', 'bar.*']); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertFalse($fileStaged->isTrue($io, $repository)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|