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
|
|
|
|