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\Config; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class HookTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Tests Hook::__construct |
20
|
|
|
*/ |
21
|
|
|
public function testDisabledByDefault(): void |
22
|
|
|
{ |
23
|
|
|
$hook = new Hook('pre-commit'); |
24
|
|
|
$config = $hook->getJsonData(); |
25
|
|
|
|
26
|
|
|
$this->assertFalse($hook->isEnabled()); |
27
|
|
|
$this->assertFalse($config['enabled']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Tests Hook::setEnabled |
32
|
|
|
*/ |
33
|
|
|
public function testSetEnabled(): void |
34
|
|
|
{ |
35
|
|
|
$hook = new Hook('pre-commit'); |
36
|
|
|
$hook->setEnabled(true); |
37
|
|
|
$config = $hook->getJsonData(); |
38
|
|
|
|
39
|
|
|
$this->assertTrue($hook->isEnabled()); |
40
|
|
|
$this->assertTrue($config['enabled']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Tests Hook::__construct |
45
|
|
|
*/ |
46
|
|
|
public function testEmptyActions(): void |
47
|
|
|
{ |
48
|
|
|
$hook = new Hook('pre-commit'); |
49
|
|
|
$config = $hook->getJsonData(); |
50
|
|
|
|
51
|
|
|
$this->assertCount(0, $hook->getActions()); |
52
|
|
|
$this->assertCount(0, $config['actions']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tests Hook::addAction |
57
|
|
|
*/ |
58
|
|
|
public function testAddAction(): void |
59
|
|
|
{ |
60
|
|
|
$hook = new Hook('pre-commit'); |
61
|
|
|
$hook->addAction(new Action('\\Foo\\Bar')); |
62
|
|
|
$config = $hook->getJsonData(); |
63
|
|
|
|
64
|
|
|
$this->assertCount(1, $hook->getActions()); |
65
|
|
|
$this->assertCount(1, $config['actions']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Tests Hook::addAction |
70
|
|
|
*/ |
71
|
|
|
public function testAddMultiAction(): void |
72
|
|
|
{ |
73
|
|
|
$hook = new Hook('pre-commit'); |
74
|
|
|
$hook->addAction(new Action('\\Foo\\Bar'), new Action('\\Foo\\Bar')); |
75
|
|
|
$config = $hook->getJsonData(); |
76
|
|
|
|
77
|
|
|
$this->assertCount(2, $hook->getActions()); |
78
|
|
|
$this->assertCount(2, $config['actions']); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|