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 ActionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testItCanAllowFailure(): void |
19
|
|
|
{ |
20
|
|
|
$action = new Action('\\Foo\\Bar', [], [], ['allow-failure' => true]); |
21
|
|
|
$this->assertTrue($action->isFailureAllowed()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testItDoesNotAllowFailureByDefault(): void |
25
|
|
|
{ |
26
|
|
|
// nothing configured so should not be allowed |
27
|
|
|
$action = new Action('\\Foo\\Bar', [], [], []); |
28
|
|
|
$this->assertFalse($action->isFailureAllowed()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testItAllowsChangingTheFailureDefault(): void |
32
|
|
|
{ |
33
|
|
|
$action = new Action('\\Foo\\Bar'); |
34
|
|
|
$this->assertTrue($action->isFailureAllowed(true)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testFailureCanBeExplicitlyDisallowed(): void |
38
|
|
|
{ |
39
|
|
|
$action = new Action('\\Foo\\Bar', [], [], ['allow-failure' => false]); |
40
|
|
|
$this->assertFalse($action->isFailureAllowed(true)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testItProvidesAccessToTheAction(): void |
44
|
|
|
{ |
45
|
|
|
$action = new Action('\\Foo\\Bar'); |
46
|
|
|
$this->assertEquals('\\Foo\\Bar', $action->getAction()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testItProvidesAccessToTheLabel(): void |
50
|
|
|
{ |
51
|
|
|
$action = new Action('\\Foo\\Bar', [], [], ['label' => 'My label']); |
52
|
|
|
$this->assertEquals('My label', $action->getLabel()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testTheLabelIsEmptyByDefault(): void |
56
|
|
|
{ |
57
|
|
|
$action = new Action('\\Foo\\Bar'); |
58
|
|
|
$this->assertEquals('\\Foo\\Bar', $action->getLabel()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testItProvidedAccessToTheOptions(): void |
62
|
|
|
{ |
63
|
|
|
$action = new Action('\\Foo\\Bar'); |
64
|
|
|
$this->assertEquals([], $action->getOptions()->getAll()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testThatOptionsAreEmptyByDefault(): void |
68
|
|
|
{ |
69
|
|
|
$action = new Action('\\Foo\\Bar'); |
70
|
|
|
$config = $action->getJsonData(); |
71
|
|
|
$this->assertCount(1, $config); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @throws \Exception |
76
|
|
|
*/ |
77
|
|
|
public function testConditionsGetExportedToJson(): void |
78
|
|
|
{ |
79
|
|
|
$conditions = [ |
80
|
|
|
['exec' => '\\Foo\\Bar', 'args' => []] |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$action = new Action('\\Foo\\Bar', [], $conditions); |
84
|
|
|
$config = $action->getJsonData(); |
85
|
|
|
$this->assertCount(1, $config['conditions']); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @throws \Exception |
90
|
|
|
*/ |
91
|
|
|
public function testItProvidesAccessToConditions(): void |
92
|
|
|
{ |
93
|
|
|
$conditions = [ |
94
|
|
|
['exec' => '\\Foo\\Bar', 'args' => []], |
95
|
|
|
['exec' => '\\Fiz\\Baz', 'args' => []] |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
$action = new Action('\\Foo\\Bar', [], $conditions); |
99
|
|
|
$this->assertCount(2, $action->getConditions()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testSettingsWillBeExportedToJson(): void |
103
|
|
|
{ |
104
|
|
|
$action = new Action('\\Foo\\Bar', [], [], ['allow-failure' => true]); |
105
|
|
|
$config = $action->getJsonData(); |
106
|
|
|
$this->assertCount(1, $config['config']); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|