Skip to content

Commit 80fa0f4

Browse files
Added tests for the new multiple hooks specifying mechanism
1 parent a34ff52 commit 80fa0f4

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

tests/unit/Console/Command/InstallTest.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,99 @@ public function testInstallPreCommitHook(): void
114114

115115
$this->assertTrue($repo->hookExists('pre-commit'));
116116
}
117+
118+
/**
119+
* Tests Install::run
120+
*
121+
* @throws \Exception
122+
*/
123+
public function testInstallMultipleHooks(): void
124+
{
125+
$repo = new DummyRepo();
126+
$output = new NullOutput();
127+
$input = new ArrayInput(
128+
[
129+
'hook' => 'pre-commit,pre-push,post-checkout',
130+
'--configuration' => CH_PATH_FILES . '/template/captainhook.json',
131+
'--git-directory' => $repo->getGitDir()
132+
]
133+
);
134+
135+
$install = new Install(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
136+
$install->run($input, $output);
137+
138+
$this->assertTrue($repo->hookExists('pre-commit'));
139+
$this->assertTrue($repo->hookExists('pre-push'));
140+
$this->assertTrue($repo->hookExists('post-checkout'));
141+
}
142+
143+
/**
144+
* Tests Install::run
145+
*
146+
* @throws \Exception
147+
*/
148+
public function testInstallMultipleHooksWithSpacesAfterAndBetweenSeparator(): void
149+
{
150+
$repo = new DummyRepo();
151+
$output = new NullOutput();
152+
$input = new ArrayInput(
153+
[
154+
'hook' => ' pre-commit , pre-push , post-checkout, post-commit',
155+
'--configuration' => CH_PATH_FILES . '/template/captainhook.json',
156+
'--git-directory' => $repo->getGitDir()
157+
]
158+
);
159+
160+
$install = new Install(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
161+
$install->run($input, $output);
162+
163+
$this->assertTrue($repo->hookExists('pre-commit'));
164+
$this->assertTrue($repo->hookExists('pre-push'));
165+
$this->assertTrue($repo->hookExists('post-checkout'));
166+
}
167+
168+
/**
169+
* Tests Install::run
170+
*
171+
* @throws \Exception
172+
*/
173+
public function testInstallMultipleHooksWithOneWrong(): void
174+
{
175+
$this->expectException(\CaptainHook\App\Exception\InvalidHookName::class);
176+
$repo = new DummyRepo();
177+
$output = new NullOutput();
178+
$input = new ArrayInput(
179+
[
180+
'hook' => 'pre-commit,pre-push,post-checkout,something-wrong',
181+
'--configuration' => CH_PATH_FILES . '/template/captainhook.json',
182+
'--git-directory' => $repo->getGitDir()
183+
]
184+
);
185+
186+
$install = new Install(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
187+
$install->run($input, $output);
188+
}
189+
190+
191+
/**
192+
* Tests Install::run
193+
*
194+
* @throws \Exception
195+
*/
196+
public function testInstallMultipleHooksWithMultipleWrong(): void
197+
{
198+
$this->expectException(\CaptainHook\App\Exception\InvalidHookName::class);
199+
$repo = new DummyRepo();
200+
$output = new NullOutput();
201+
$input = new ArrayInput(
202+
[
203+
'hook' => 'pre-commit,pre-push,post-checkout,something-wrong1,something-wrong2',
204+
'--configuration' => CH_PATH_FILES . '/template/captainhook.json',
205+
'--git-directory' => $repo->getGitDir()
206+
]
207+
);
208+
209+
$install = new Install(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
210+
$install->run($input, $output);
211+
}
117212
}

tests/unit/Runner/InstallerTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public function testSetInvalidHook(): void
4747
$runner->setHook('itDoNotExist');
4848
}
4949

50+
/**
51+
* Tests Installer::setHook
52+
*
53+
* @throws \CaptainHook\App\Exception\InvalidHookName
54+
*/
55+
public function testSetMultipleInvalidHooks(): void
56+
{
57+
$this->expectException(InvalidHookName::class);
58+
59+
$io = $this->createIOMock();
60+
$config = $this->createConfigMock();
61+
$repo = $this->createRepositoryMock();
62+
$template = $this->createTemplateMock();
63+
64+
$runner = new Installer($io, $config, $repo, $template);
65+
$runner->setHook('itDoNotExist1,itDoNotExist2,itDontExist3');
66+
}
67+
5068
/**
5169
* Tests Installer::setHook
5270
*
@@ -132,6 +150,27 @@ public function testWriteHook(): void
132150
$this->assertFileExists($fakeRepo->getHookDir() . '/pre-commit');
133151
}
134152

153+
/**
154+
* Tests Installer::run
155+
*/
156+
public function testWriteMultipleHooks(): void
157+
{
158+
$fakeRepo = new DummyRepo();
159+
160+
$io = $this->createIOMock();
161+
$config = $this->createConfigMock();
162+
$repo = $this->createRepositoryMock($fakeRepo->getRoot());
163+
$template = $this->createTemplateMock();
164+
165+
$runner = new Installer($io, $config, $repo, $template);
166+
$runner->setHook('pre-commit,pre-push,post-checkout');
167+
$runner->run();
168+
169+
$this->assertFileExists($fakeRepo->getHookDir() . '/pre-commit');
170+
$this->assertFileExists($fakeRepo->getHookDir() . '/pre-push');
171+
$this->assertFileExists($fakeRepo->getHookDir() . '/post-checkout');
172+
}
173+
135174
/**
136175
* Tests Installer::run
137176
*/

0 commit comments

Comments
 (0)