Skip to content

Commit 5c5c406

Browse files
Increase templating test coverage
1 parent 3cb0b14 commit 5c5c406

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/unit/Hook/Template/BuilderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ public function testBuildLocalTemplate(): void
112112
$this->assertStringContainsString('$captainHook->run', $code);
113113
}
114114

115+
/**
116+
* Tests Builder::build
117+
*/
118+
public function testBuildBootstrapNotFound(): void
119+
{
120+
$this->expectException(Exception::class);
121+
122+
$resolver = $this->createResolverMock(CH_PATH_FILES . '/bin/captainhook', false);
123+
$repository = $this->createRepositoryMock(CH_PATH_FILES);
124+
$config = $this->createConfigMock(true, CH_PATH_FILES . '/template/captainhook.json');
125+
$config->method('getRunMode')->willReturn('php');
126+
$config->method('getRunExec')->willReturn('');
127+
$config->method('getBootstrap')->willReturn('vendorXX/autoload.php');
128+
129+
$template = Builder::build($config, $repository, $resolver);
130+
$this->assertInstanceOf(Local\PHP::class, $template);
131+
132+
$code = $template->getCode('pre-commit');
133+
$this->assertStringContainsString('pre-commit', $code);
134+
$this->assertStringContainsString('$captainHook->run', $code);
135+
}
136+
115137
/**
116138
* Tests Builder::build
117139
*/

tests/unit/Hook/Template/Local/PHPTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ public function testSrcTemplateExtExecutable(): void
5959
$this->assertStringContainsString('$captainHook->run(', $code);
6060
}
6161

62+
/**
63+
* Tests PHP::getCode
64+
*/
65+
public function testPharAbsoluteExecutablePath(): void
66+
{
67+
$pathInfo = $this->createMock(PathInfo::class);
68+
$pathInfo->method('getExecutablePath')->willReturn('/usr/local/bin/captainhook');
69+
$pathInfo->method('getConfigPath')->willReturn('captainhook.json');
70+
71+
$config = $this->createConfigMock(false, 'captainhook.json');
72+
$config->method('getBootstrap')->willReturn('vendor/autoload.php');
73+
74+
$template = new PHP($pathInfo, $config, true);
75+
$code = $template->getCode('commit-msg');
76+
77+
$this->assertStringContainsString('#!/usr/bin/env php', $code);
78+
$this->assertStringContainsString('commit-msg', $code);
79+
$this->assertStringContainsString('/usr/local/bin/captainhook', $code);
80+
}
81+
6282
/**
6383
* Tests PHP::getCode
6484
*/

0 commit comments

Comments
 (0)