Passed
Push — main ( dfc89b...2df285 )
by Sebastian
01:01 queued 10s
created

testFindsConditionClassByShorthand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 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\Runner;
13
14
use Exception;
15
use PHPUnit\Framework\TestCase;
16
17
class ShorthandTest extends TestCase
18
{
19
    /**
20
     * Checks if shorthands are identified correctly
21
     */
22
    public function testCanIdentifyShorthand()
23
    {
24
        // negative
25
        $this->assertFalse(Shorthand::isShorthand('foo'));
26
        $this->assertFalse(Shorthand::isShorthand('\\CaptainHook\\App'));
27
        $this->assertFalse(Shorthand::isShorthand('CaptainHook.'));
28
        $this->assertFalse(Shorthand::isShorthand('captainhook.sh'));
29
30
        // positive
31
        $this->assertTrue(Shorthand::isShorthand('CaptainHook.foo.fiz'));
32
        $this->assertTrue(Shorthand::isShorthand('captainhook.Bar.Baz'));
33
        $this->assertTrue(Shorthand::isShorthand('CAPTAINHOOK.FOO.BAR'));
34
    }
35
36
    /**
37
     * Check if invalid shorthand detection works
38
     */
39
    public function testDetectsInvalidActionShortHand(): void
40
    {
41
        $this->expectException(Exception::class);
42
        Shorthand::getActionClass('Captainhook.foo.bar.baz');
43
    }
44
45
    /**
46
     * Check if an invalid shorthand group is detected
47
     */
48
    public function testDetectsInvalidActionShorthandGroup(): void
49
    {
50
        $this->expectException(Exception::class);
51
        Shorthand::getActionClass('Captainhook.foo.bar');
52
    }
53
54
    /**
55
     * Check if an invalid action shorthand name is detected
56
     */
57
    public function testDetectsInvalidActionShorthandName(): void
58
    {
59
        $this->expectException(Exception::class);
60
        Shorthand::getActionClass('Captainhook.File.bar');
61
    }
62
63
    /**
64
     * Check if an invalid condition shorthand name is detected
65
     */
66
    public function testDetectsInvalidConditionShorthandName(): void
67
    {
68
        $this->expectException(Exception::class);
69
        Shorthand::getConditionClass('Captainhook.FileStaged.bar');
70
    }
71
72
    /**
73
     * Check if a valid action shorthand is mapped correctly
74
     */
75
    public function testFindsActionClassByShorthand(): void
76
    {
77
        $class = Shorthand::getActionClass('Captainhook.Branch.EnsureNaming');
78
        $this->assertTrue(str_contains($class, 'CaptainHook\App\Hook\Branch\Action\EnsureNaming'));
79
    }
80
81
    /**
82
     * Check if a valid condition shorthand is mapped correctly
83
     */
84
    public function testFindsConditionClassByShorthand(): void
85
    {
86
        $class = Shorthand::getConditionClass('Captainhook.Status.OnBranch');
87
        $this->assertTrue(str_contains($class, 'CaptainHook\App\Hook\Condition\Branch\On'));
88
    }
89
}
90