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
|
|
|
/** |
24
|
|
|
* Tests Any::isTrue |
25
|
|
|
*/ |
26
|
|
|
public function testIsTrue(): void |
27
|
|
|
{ |
28
|
|
|
$io = $this->createIOMock(); |
29
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']); |
30
|
|
|
$repository = $this->createRepositoryMock(''); |
31
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
32
|
|
|
|
33
|
|
|
$fileStaged = new Any(['foo.php', 'bar.php']); |
34
|
|
|
|
35
|
|
|
$this->assertTrue($fileStaged->isTrue($io, $repository)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Tests Any::isTrue |
40
|
|
|
*/ |
41
|
|
|
public function testWithWildcardIsTrue(): void |
42
|
|
|
{ |
43
|
|
|
$io = $this->createIOMock(); |
44
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php', 'foo.php']); |
45
|
|
|
$repository = $this->createRepositoryMock(''); |
46
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
47
|
|
|
|
48
|
|
|
$fileStaged = new Any(['foo.*', 'bar.php']); |
49
|
|
|
|
50
|
|
|
$this->assertTrue($fileStaged->isTrue($io, $repository)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Tests Any::isTrue |
55
|
|
|
*/ |
56
|
|
|
public function testIsFalse(): void |
57
|
|
|
{ |
58
|
|
|
$io = $this->createIOMock(); |
59
|
|
|
$operator = $this->createGitIndexOperator(['fiz.php', 'baz.php']); |
60
|
|
|
$repository = $this->createRepositoryMock(''); |
61
|
|
|
$repository->expects($this->once())->method('getIndexOperator')->willReturn($operator); |
62
|
|
|
|
63
|
|
|
$fileStaged = new Any(['foo.php', 'bar.php']); |
64
|
|
|
|
65
|
|
|
$this->assertFalse($fileStaged->isTrue($io, $repository)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Tests Any::isTrue |
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
|
|
|
|