RestrictionTest::testIsApplicableWithVirtualHook()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
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;
13
14
use PHPUnit\Framework\TestCase;
15
16
class RestrictionTest extends TestCase
17
{
18
    public function testIsApplicableFromArray(): void
19
    {
20
        $restriction = Restriction::fromArray(['pre-commit', 'pre-push']);
21
22
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
23
        $this->assertTrue($restriction->isApplicableFor('pre-push'));
24
        $this->assertFalse($restriction->isApplicableFor('post-push'));
25
    }
26
27
    public function testIsApplicableFromString(): void
28
    {
29
        $restriction = Restriction::fromString('pre-commit');
30
31
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
32
        $this->assertFalse($restriction->isApplicableFor('post-push'));
33
    }
34
35
    public function testIsApplicableEmpty(): void
36
    {
37
        $restriction = Restriction::empty();
38
39
        $this->assertFalse($restriction->isApplicableFor('pre-commit'));
40
        $this->assertFalse($restriction->isApplicableFor('post-push'));
41
    }
42
43
    public function testIsApplicableEmptyAddingRestrictions(): void
44
    {
45
        $restriction = Restriction::empty()->with('pre-commit');
46
47
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
48
        $this->assertFalse($restriction->isApplicableFor('post-push'));
49
    }
50
51
    public function testIsApplicableWithAlreadyApplicableRestrictions(): void
52
    {
53
        $restriction = Restriction::fromString('pre-commit')->with('pre-commit');
54
55
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
56
        $this->assertFalse($restriction->isApplicableFor('post-push'));
57
    }
58
59
    public function testIsApplicableWithVirtualHook(): void
60
    {
61
        $restriction = Restriction::fromString('post-change');
62
63
        $this->assertTrue($restriction->isApplicableFor('post-checkout'));
64
        $this->assertTrue($restriction->isApplicableFor('post-merge'));
65
        $this->assertTrue($restriction->isApplicableFor('post-rewrite'));
66
    }
67
}
68