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
112
112
$ this ->assertStringContainsString ('$captainHook->run ' , $ code );
113
113
}
114
114
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
+
115
137
/**
116
138
* Tests Builder::build
117
139
*/
Original file line number Diff line number Diff line change @@ -59,6 +59,26 @@ public function testSrcTemplateExtExecutable(): void
59
59
$ this ->assertStringContainsString ('$captainHook->run( ' , $ code );
60
60
}
61
61
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
+
62
82
/**
63
83
* Tests PHP::getCode
64
84
*/
You can’t perform that action at this time.
0 commit comments