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\Logic; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO\Mockery as IOMockery; |
15
|
|
|
use CaptainHook\App\Hook\Condition; |
16
|
|
|
use CaptainHook\App\Mockery as AppMockery; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class LogicAndTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use IOMockery; |
22
|
|
|
use AppMockery; |
23
|
|
|
|
24
|
|
|
public function testLogicAndReturnsFalseWithOneFailure(): void |
25
|
|
|
{ |
26
|
|
|
$io = $this->createIOMock(); |
27
|
|
|
$repository = $this->createRepositoryMock(); |
28
|
|
|
$true = $this->getMockBuilder(Condition::class)->getMock(); |
29
|
|
|
$false = $this->getMockBuilder(Condition::class)->getMock(); |
30
|
|
|
|
31
|
|
|
$true->method('isTrue')->willReturn(true); |
32
|
|
|
$false->method('isTrue')->willReturn(false); |
33
|
|
|
|
34
|
|
|
$condition = LogicAnd::fromConditionsArray([$true, $false]); |
35
|
|
|
|
36
|
|
|
$this->assertFalse($condition->isTrue($io, $repository)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testLogicAndReturnsTrueWithAllSuccess(): void |
40
|
|
|
{ |
41
|
|
|
$io = $this->createIOMock(); |
42
|
|
|
$repository = $this->createRepositoryMock(); |
43
|
|
|
$true = $this->getMockBuilder(Condition::class)->getMock(); |
44
|
|
|
|
45
|
|
|
$true->method('isTrue')->willReturn(true); |
46
|
|
|
|
47
|
|
|
$condition = LogicAnd::fromConditionsArray([$true, $true, $true]); |
48
|
|
|
|
49
|
|
|
$this->assertTrue($condition->isTrue($io, $repository)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testNamedConstructorIgnoresNonCondition(): void |
53
|
|
|
{ |
54
|
|
|
$io = $this->createIOMock(); |
55
|
|
|
$repository = $this->createRepositoryMock(); |
56
|
|
|
$true = $this->getMockBuilder(Condition::class)->getMock(); |
57
|
|
|
$true->expects($this->exactly(2))->method('isTrue')->willReturn(true); |
58
|
|
|
|
59
|
|
|
$condition = LogicAnd::fromConditionsArray([$true, 'string', $true]); |
60
|
|
|
|
61
|
|
|
$this->assertTrue($condition->isTrue($io, $repository)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|