Passed
Push — main ( be5608...0f0048 )
by Sebastian
04:11
created

NotOnMatchingTest::testConditionTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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\Branch;
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 NotOnMatchingTest extends TestCase
19
{
20
    use IOMockery;
21
    use AppMockery;
22
23
    /**
24
     * Tests NotOnMatching::isTrue
25
     */
26
    public function testConditionFalse(): void
27
    {
28
        $io           = $this->createIOMock();
29
        $repository   = $this->createRepositoryMock();
30
        $infoOperator = $this->createGitInfoOperator('', 'feature/ABC-1234');
31
        $infoOperator->expects($this->once())->method('getCurrentBranch');
32
        $repository->expects($this->once())->method('getInfoOperator')->willReturn($infoOperator);
33
34
        $condition = new NotOnMatching('#feature/[A-Z0-9\\-_]+#i');
35
        $this->assertFalse($condition->isTrue($io, $repository));
36
    }
37
38
    /**
39
     * Tests NotOnMatching::isTrue
40
     */
41
    public function testConditionTrue(): void
42
    {
43
        $io           = $this->createIOMock();
44
        $repository   = $this->createRepositoryMock();
45
        $infoOperator = $this->createGitInfoOperator();
46
        $infoOperator->expects($this->once())->method('getCurrentBranch')->willReturn('dev');
47
        $repository->expects($this->once())->method('getInfoOperator')->willReturn($infoOperator);
48
49
        $condition = new NotOnMatching('#feature/[a-z0-9\-_]+#i');
50
        $this->assertTrue($condition->isTrue($io, $repository));
51
    }
52
}
53