Skip to content

Commit 6e2f548

Browse files
Add new getter for all hook configs
1 parent de57db5 commit 6e2f548

File tree

2 files changed

+38
-90
lines changed

2 files changed

+38
-90
lines changed

src/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ public function getHookConfig(string $hook): Config\Hook
345345
return $this->hooks[$hook];
346346
}
347347

348+
/**
349+
* Return hook configs
350+
*
351+
* @return array<string, \CaptainHook\App\Config\Hook>
352+
*/
353+
public function getHookConfigs(): array
354+
{
355+
return $this->hooks;
356+
}
357+
348358
/**
349359
* Returns a hook config containing all the actions to execute
350360
*

tests/unit/ConfigTest.php

Lines changed: 28 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,32 @@
1919

2020
class ConfigTest extends TestCase
2121
{
22-
/**
23-
* Tests Config::__construct
24-
*/
25-
public function testConstructor(): void
22+
public function testItCanBeCreatedWithoutFile(): void
2623
{
2724
$config = new Config('./no-config.json');
2825
$this->assertFalse($config->isLoadedFromFile());
2926
}
3027

31-
/**
32-
* Tests Config::isLoadedFromFile
33-
*/
34-
public function testIsLoadedFromFile(): void
28+
public function testItCanBeLoadedFromFile(): void
3529
{
3630
$config = new Config('valid.json', true);
3731
$this->assertTrue($config->isLoadedFromFile());
3832
}
3933

40-
/**
41-
* Tests Config::getHookConfig
42-
*/
43-
public function testGetInvalidHook(): void
34+
public function testItCanReturnAllHookConfigs(): void
35+
{
36+
$config = new Config('valid.json', true);
37+
$this->assertNotEmpty($config->getHookConfigs());
38+
}
39+
40+
public function testItDoesNotAllowInvalidHookNames(): void
4441
{
4542
$this->expectException(Exception::class);
4643
$config = new Config('./no-config.json');
4744
$config->getHookConfig('foo');
4845
}
4946

50-
/**
51-
* Tests Config::getHookConfigToExecute
52-
*/
53-
public function testGetHookConfigWithVirtualHooks(): void
47+
public function testItCombinesHooksAndVirtualHookConfigurations(): void
5448
{
5549
$config = new Config('./no-config.json');
5650
$config->getHookConfig('post-rewrite')->setEnabled(true);
@@ -63,154 +57,107 @@ public function testGetHookConfigWithVirtualHooks(): void
6357
$this->assertCount(2, $hookConfig->getActions());
6458
}
6559

66-
/**
67-
* Tests Config::getGitDirectory
68-
*/
69-
public function testAssumeCwdAsGitDir(): void
60+
public function testItAssumesCwdAsGitDir(): void
7061
{
7162
$config = new Config('./no-config.json');
7263
$this->assertEquals(getcwd() . '/.git', $config->getGitDirectory());
7364
}
7465

75-
/**
76-
* Tests Config::getPath
77-
*/
78-
public function testGetPath(): void
66+
public function testItCanReturnTheConfigurationPath(): void
7967
{
8068
$path = realpath(__DIR__ . '/../files/config/valid.json');
8169
$config = new Config($path);
8270

8371
$this->assertEquals($path, $config->getPath());
8472
}
8573

86-
/**
87-
* Tests Config::getBootstrap
88-
*/
89-
public function testGetBootstrapDefault(): void
74+
public function testIsHasABootstrapDefault(): void
9075
{
9176
$path = realpath(__DIR__ . '/../files/config/valid.json');
9277
$config = new Config($path);
9378

9479
$this->assertEquals('vendor/autoload.php', $config->getBootstrap());
9580
}
9681

97-
/**
98-
* Tests Config::getBootstrap
99-
*/
100-
public function testGetBootstrapSetting(): void
82+
public function testItCanSetTheBootstrap(): void
10183
{
10284
$path = realpath(__DIR__ . '/../files/config/valid.json');
10385
$config = new Config($path, true, ['bootstrap' => 'libs/autoload.php']);
10486

10587
$this->assertEquals('libs/autoload.php', $config->getBootstrap());
10688
}
10789

108-
/**
109-
* Tests Config::isFailureAllowed
110-
*/
111-
public function testIsFailureAllowedDefault(): void
90+
public function testNoFailuresAreAllowedByDefault(): void
11291
{
11392
$path = realpath(__DIR__ . '/../files/config/valid.json');
11493
$config = new Config($path, true);
11594

11695
$this->assertFalse($config->isFailureAllowed());
11796
}
11897

119-
/**
120-
* Tests Config::isFailureAllowed
121-
*/
122-
public function testIsFailureAllowedSet(): void
98+
public function testAllowFailureCanBeChanged(): void
12399
{
124100
$path = realpath(__DIR__ . '/../files/config/valid.json');
125101
$config = new Config($path, true, ['allow-failure' => true]);
126102

127103
$this->assertTrue($config->isFailureAllowed());
128104
}
129-
/**
130-
* Tests Config::useAnsiColors
131-
*/
132-
public function testAnsiColorsEnabledByDefault(): void
105+
106+
public function testColorsAreEnabledByDefault(): void
133107
{
134108
$config = new Config('foo.json', true);
135109
$this->assertTrue($config->useAnsiColors());
136110
}
137111

138-
/**
139-
* Tests Config::useAnsiColors
140-
*/
141-
public function testDisableAnsiColors(): void
112+
public function testAnsiColorsCanBeDisabled(): void
142113
{
143114
$config = new Config('foo.json', true, ['ansi-colors' => false]);
144115
$this->assertFalse($config->useAnsiColors());
145116
}
146117

147-
/**
148-
* Tests Config::getRunMode
149-
*/
150-
public function testGetRunMode(): void
118+
public function testProvidesAccessToRunMode(): void
151119
{
152120
$config = new Config('foo.json', true, ['run-mode' => 'docker', 'run-exec' => 'foo']);
153121
$this->assertEquals('docker', $config->getRunConfig()->getMode());
154122
}
155123

156-
/**
157-
* Tests Config::getRunExec
158-
*/
159-
public function testGetRunExec(): void
124+
public function testProvidesAccessToRunExec(): void
160125
{
161126
$config = new Config('foo.json', true, ['run-mode' => 'docker', 'run-exec' => 'foo']);
162127
$this->assertEquals('foo', $config->getRunConfig()->getDockerCommand());
163128
}
164129

165-
/**
166-
* Tests Config::getRunPath
167-
*/
168-
public function testGetRunPathEmptyByDefault(): void
130+
public function testRunPathIsEmptyByDefault(): void
169131
{
170132
$config = new Config('foo.json', true, ['run-mode' => 'docker', 'run-exec' => 'foo']);
171133
$this->assertEquals('', $config->getRunConfig()->getCaptainsPath());
172134
}
173135

174-
/**
175-
* Tests Config::getCustomSettings
176-
*/
177-
public function testGetCustomSettings(): void
136+
public function testAllowsCustomSettings(): void
178137
{
179138
$config = new Config('foo.json', true, ['custom' => ['foo' => 'foo']]);
180139
$this->assertEquals(['foo' => 'foo'], $config->getCustomSettings());
181140
}
182141

183-
/**
184-
* Tests Config::getRunPath
185-
*/
186-
public function testGetRunPath(): void
142+
public function testProvidesAccessToRunPath(): void
187143
{
188144
$config = new Config('foo.json', true, ['run-mode' => 'docker', 'run-exec' => 'foo', 'run-path' => '/foo']);
189145
$this->assertEquals('/foo', $config->getRunConfig()->getCaptainsPath());
190146
}
191147

192-
/**
193-
* Tests Config::failOnFirstError default
194-
*/
195-
public function testFailOnFirstErrorDefault(): void
148+
public function testFailOnFirstErrorIsTrueByDefault(): void
196149
{
197150
$config = new Config('foo.json', true, []);
198151
$this->assertTrue($config->failOnFirstError());
199152
}
200153

201-
/**
202-
* Tests Config::failOnFirstError
203-
*/
204-
public function testFailOnFirstError(): void
154+
public function testFailOnFirstErrorCanBeChanged(): void
205155
{
206156
$config = new Config('foo.json', true, ['fail-on-first-error' => false]);
207157
$this->assertFalse($config->failOnFirstError());
208158
}
209159

210-
/**
211-
* Tests Config::getJsonData
212-
*/
213-
public function testGetJsonData(): void
160+
public function testCanBeExportedToJsonData(): void
214161
{
215162
$config = new Config('./no-config.json');
216163
$json = $config->getJsonData();
@@ -221,10 +168,7 @@ public function testGetJsonData(): void
221168
$this->assertIsArray($json['pre-push']);
222169
}
223170

224-
/**
225-
* Tests Config::getJsonData
226-
*/
227-
public function testGetJsonDataWithSettings(): void
171+
public function testCanBeExportedToJsonDataWithSettings(): void
228172
{
229173
$config = new Config(
230174
'./no-config.json',
@@ -241,9 +185,6 @@ public function testGetJsonDataWithSettings(): void
241185
$this->assertIsArray($json['pre-push']);
242186
}
243187

244-
/**
245-
* Tests Config::getJsonData
246-
*/
247188
public function testGetJsonDataWithoutEmptyConfig(): void
248189
{
249190
$config = new Config('foo.json', true, []);
@@ -252,9 +193,6 @@ public function testGetJsonDataWithoutEmptyConfig(): void
252193
$this->assertArrayNotHasKey('config', $json);
253194
}
254195

255-
/**
256-
* Tests Config::getJsonData
257-
*/
258196
public function testGetJsonDataWithConfigSection(): void
259197
{
260198
$config = new Config('foo.json', true, ['run-mode' => 'docker', 'run-exec' => 'foo']);

0 commit comments

Comments
 (0)