File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 */
You can’t perform that action at this time.
0 commit comments