Passed
Push — master ( f6d3c0...f5019c )
by Sebastian
01:52
created

testIsApplicableWithAlreadyApplicableRestrictions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
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
    /**
19
     * Tests Restriction::isApplicable
20
     */
21
    public function testIsApplicableFromArray(): void
22
    {
23
        $restriction = Restriction::fromArray(['pre-commit', 'pre-push']);
24
25
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
26
        $this->assertTrue($restriction->isApplicableFor('pre-push'));
27
        $this->assertFalse($restriction->isApplicableFor('post-push'));
28
    }
29
30
    /**
31
     * Tests Restriction::isApplicable
32
     */
33
    public function testIsApplicableFromString(): void
34
    {
35
        $restriction = Restriction::fromString('pre-commit');
36
37
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
38
        $this->assertFalse($restriction->isApplicableFor('post-push'));
39
    }
40
41
    /**
42
     * Tests Restriction::isApplicable
43
     */
44
    public function testIsApplicableEmpty(): void
45
    {
46
        $restriction = Restriction::empty();
47
48
        $this->assertFalse($restriction->isApplicableFor('pre-commit'));
49
        $this->assertFalse($restriction->isApplicableFor('post-push'));
50
    }
51
52
    /**
53
     * Tests Restriction::isApplicable
54
     */
55
    public function testIsApplicableEmptyAddingRestrictions(): void
56
    {
57
        $restriction = Restriction::empty()->with('pre-commit');
58
59
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
60
        $this->assertFalse($restriction->isApplicableFor('post-push'));
61
    }
62
63
    /**
64
     * Tests Restriction::isApplicable
65
     */
66
    public function testIsApplicableWithAlreadyApplicableRestrictions(): void
67
    {
68
        $restriction = Restriction::fromString('pre-commit')->with('pre-commit');
69
70
        $this->assertTrue($restriction->isApplicableFor('pre-commit'));
71
        $this->assertFalse($restriction->isApplicableFor('post-push'));
72
    }
73
}
74