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; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
16
|
|
|
use CaptainHook\App\Mockery as AppMockery; |
17
|
|
|
|
18
|
|
|
class OnBranchTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
use IOMockery; |
21
|
|
|
use AppMockery; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Tests OnBranch::isTrue |
25
|
|
|
*/ |
26
|
|
|
public function testConditionTrue(): void |
27
|
|
|
{ |
28
|
|
|
$io = $this->createIOMock(); |
29
|
|
|
$repository = $this->createRepositoryMock(); |
30
|
|
|
$infoOperator = $this->createGitInfoOperator(); |
31
|
|
|
$infoOperator->expects($this->once())->method('getCurrentBranch')->willReturn('master'); |
32
|
|
|
$repository->expects($this->once())->method('getInfoOperator')->willReturn($infoOperator); |
33
|
|
|
|
34
|
|
|
$condition = new OnBranch('master'); |
35
|
|
|
|
36
|
|
|
$this->assertTrue($condition->isTrue($io, $repository)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Tests OnBranch::isTrue |
41
|
|
|
*/ |
42
|
|
|
public function testConditionFalse(): void |
43
|
|
|
{ |
44
|
|
|
$io = $this->createIOMock(); |
45
|
|
|
$repository = $this->createRepositoryMock(); |
46
|
|
|
$infoOperator = $this->createGitInfoOperator(); |
47
|
|
|
$infoOperator->expects($this->once())->method('getCurrentBranch')->willReturn('master'); |
48
|
|
|
$repository->expects($this->once())->method('getInfoOperator')->willReturn($infoOperator); |
49
|
|
|
|
50
|
|
|
$condition = new OnBranch('development'); |
51
|
|
|
|
52
|
|
|
$this->assertFalse($condition->isTrue($io, $repository)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|