File tree Expand file tree Collapse file tree 2 files changed +40
-5
lines changed
tests/unit/Hook/Template/Local Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,6 @@ protected function getHookLines(string $hook): array
63
63
];
64
64
}
65
65
66
- $ executable = $ this ->config ->getPhpPath () === ''
67
- ? $ this ->pathInfo ->getExecutablePath ()
68
- : $ this ->config ->getPhpPath () . ' ' . $ this ->pathInfo ->getExecutablePath ();
69
-
70
66
return array_merge (
71
67
[
72
68
'#!/bin/sh ' ,
@@ -78,12 +74,28 @@ protected function getHookLines(string $hook): array
78
74
$ useTTY ,
79
75
[
80
76
'' ,
81
- $ executable
77
+ $ this -> getExecutable ()
82
78
. ' $INTERACTIVE '
83
79
. ' --configuration= ' . $ this ->pathInfo ->getConfigPath ()
84
80
. ' --bootstrap= ' . $ this ->config ->getBootstrap ()
85
81
. ' hook: ' . $ hook . ' "$@" ' . $ useStdIn ,
86
82
]
87
83
);
88
84
}
85
+
86
+ /**
87
+ * Returns the path to the executable including a configured php executable
88
+ *
89
+ * @return string
90
+ */
91
+ private function getExecutable (): string
92
+ {
93
+ $ executable = !empty ($ this ->config ->getPhpPath ()) ? $ this ->config ->getPhpPath () . ' ' : '' ;
94
+
95
+ if (!empty ($ this ->config ->getRunPath ())) {
96
+ return $ executable . $ this ->config ->getRunPath ();
97
+ }
98
+
99
+ return $ executable . $ this ->pathInfo ->getExecutablePath ();
100
+ }
89
101
}
Original file line number Diff line number Diff line change @@ -63,6 +63,29 @@ public function testTemplateWithDefinedPHP(): void
63
63
$ this ->assertStringContainsString ('vendor/bin/captainhook $INTERACTIVE ' , $ code );
64
64
}
65
65
66
+ /**
67
+ * Tests Shell::getCode
68
+ */
69
+ public function testTemplateWithDefinedPHPAndRunPath (): void
70
+ {
71
+ $ pathInfo = $ this ->createMock (PathInfo::class);
72
+ $ pathInfo ->method ('getExecutablePath ' )->willReturn ('vendor/bin/captainhook ' );
73
+ $ pathInfo ->method ('getConfigPath ' )->willReturn ('captainhook.json ' );
74
+
75
+ $ config = $ this ->createConfigMock (false , 'captainhook.json ' );
76
+ $ config ->method ('getBootstrap ' )->willReturn ('vendor/autoload.php ' );
77
+ $ config ->method ('getPhpPath ' )->willReturn ('/usr/bin/php7.4 ' );
78
+ $ config ->method ('getRunPath ' )->willReturn ('tools/captainhook.phar ' );
79
+
80
+ $ template = new Shell ($ pathInfo , $ config , false );
81
+ $ code = $ template ->getCode ('commit-msg ' );
82
+
83
+ $ this ->assertStringContainsString ('#!/bin/sh ' , $ code );
84
+ $ this ->assertStringContainsString ('commit-msg ' , $ code );
85
+ $ this ->assertStringContainsString ('/usr/bin/php7.4 ' , $ code );
86
+ $ this ->assertStringContainsString ('tools/captainhook.phar $INTERACTIVE ' , $ code );
87
+ }
88
+
66
89
/**
67
90
* Tests Shell::getCode
68
91
*/
You can’t perform that action at this time.
0 commit comments