Passed
Pull Request — main (#277)
by Sebastian
07:10 queued 03:45
created

ShorthandTest::testDetectsInvalidActionShortHand()   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
29
        // positive
30
        $this->assertTrue(Shorthand::isShorthand('CaptainHook.foo'));
31
        $this->assertTrue(Shorthand::isShorthand('captainhook.bar'));
32
        $this->assertTrue(Shorthand::isShorthand('CAPTAINHOOK.baz'));
33
    }
34
35
    /**
36
     * Check if invalid shorthand detection works
37
     */
38
    public function testDetectsInvalidActionShortHand(): void
39
    {
40
        $this->expectException(Exception::class);
41
        Shorthand::getActionClass('Captainhook.foo.bar.baz');
42
    }
43
44
    /**
45
     * Check if an invalid shorthand group is detected
46
     */
47
    public function testDetectsInvalidActionShorthandGroup(): void
48
    {
49
        $this->expectException(Exception::class);
50
        Shorthand::getActionClass('Captainhook.foo.bar');
51
    }
52
53
    /**
54
     * Check if an invalid action shorthand name is detected
55
     */
56
    public function testDetectsInvalidActionShorthandName(): void
57
    {
58
        $this->expectException(Exception::class);
59
        Shorthand::getActionClass('Captainhook.File.bar');
60
    }
61
62
    /**
63
     * Check if an invalid condition shorthand name is detected
64
     */
65
    public function testDetectsInvalidConditionShorthandName(): void
66
    {
67
        $this->expectException(Exception::class);
68
        Shorthand::getConditionClass('Captainhook.FileStaged.bar');
69
    }
70
71
    /**
72
     * Check if a valid action shorthand is mapped correctly
73
     */
74
    public function testFindsActionClassByShorthand(): void
75
    {
76
        $class = Shorthand::getActionClass('Captainhook.Branch.EnsureNaming');
77
        $this->assertTrue(str_contains($class, 'CaptainHook\App\Hook\Branch\Action\EnsureNaming'));
78
    }
79
80
    /**
81
     * Check if a valid condition shorthand is mapped correctly
82
     */
83
    public function testFindsConditionClassByShorthand(): void
84
    {
85
        $class = Shorthand::getConditionClass('Captainhook.Status.OnBranch');
86
        $this->assertTrue(str_contains($class, 'CaptainHook\App\Hook\Condition\Branch\On'));
87
    }
88
}
89