Skip to content

Commit b156512

Browse files
committed
feat: allow PHP executor to run executables other than PHP ones
1 parent 09df7fa commit b156512

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

local/php/executor.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,11 @@ func (e *Executor) Config(loadDotEnv bool) error {
288288
}
289289
}
290290

291-
// args[0] MUST be the same as path
292-
// but as we change the path, we should update args[0] accordingly
293-
e.Args[0] = path
291+
if IsBinaryName(e.Args[0]) {
292+
// args[0] MUST be the same as path
293+
// but as we change the path, we should update args[0] accordingly
294+
e.Args[0] = path
295+
}
294296

295297
return err
296298
}

local/php/executor_test.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ func TestHelperProcess(t *testing.T) {
9999
for _, v := range os.Environ() {
100100
fmt.Println(v)
101101
}
102+
os.Exit(0)
102103
case "exit-code":
103104
code, _ := strconv.Atoi(os.Args[4])
104105
os.Exit(code)
105106
}
106-
os.Exit(0)
107+
os.Exit(1)
107108
}
108109

109110
func (s *ExecutorSuite) TestNotEnoughArgs(c *C) {
@@ -139,6 +140,63 @@ func (s *ExecutorSuite) TestForwardExitCode(c *C) {
139140
c.Assert((&Executor{BinName: "php", Args: []string{"php"}}).Execute(true), Equals, 5)
140141
}
141142

143+
func (s *ExecutorSuite) TestExecutorRunsPHP(c *C) {
144+
defer restoreExecCommand()
145+
execCommand = func(name string, arg ...string) *exec.Cmd {
146+
c.Assert(name, Equals, "../bin/php")
147+
148+
cmd := exec.Command(os.Args[0], "-test.run=TestHelperProcess", "--", "exit-code", "0")
149+
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
150+
// Set the working directory right now so that it can be changed by
151+
// calling test case
152+
cmd.Dir, _ = os.Getwd()
153+
return cmd
154+
}
155+
156+
home, err := filepath.Abs("testdata/executor")
157+
c.Assert(err, IsNil)
158+
159+
homedir.Reset()
160+
os.Setenv("HOME", home)
161+
defer homedir.Reset()
162+
163+
oldwd, _ := os.Getwd()
164+
defer os.Chdir(oldwd)
165+
os.Chdir(filepath.Join(home, "project"))
166+
defer cleanupExecutorTempFiles()
167+
168+
c.Assert((&Executor{BinName: "php", Args: []string{"php"}}).Execute(true), Equals, 0)
169+
170+
}
171+
172+
func (s *ExecutorSuite) TestBinaryOtherThanPhp(c *C) {
173+
defer restoreExecCommand()
174+
execCommand = func(name string, arg ...string) *exec.Cmd {
175+
c.Assert(name, Equals, "not-php")
176+
177+
cmd := exec.Command(os.Args[0], "-test.run=TestHelperProcess", "--", "exit-code", "0")
178+
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
179+
// Set the working directory right now so that it can be changed by
180+
// calling test case
181+
cmd.Dir, _ = os.Getwd()
182+
return cmd
183+
}
184+
185+
home, err := filepath.Abs("testdata/executor")
186+
c.Assert(err, IsNil)
187+
188+
homedir.Reset()
189+
os.Setenv("HOME", home)
190+
defer homedir.Reset()
191+
192+
oldwd, _ := os.Getwd()
193+
defer os.Chdir(oldwd)
194+
os.Chdir(filepath.Join(home, "project"))
195+
defer cleanupExecutorTempFiles()
196+
197+
c.Assert((&Executor{BinName: "php", Args: []string{"not-php"}}).Execute(true), Equals, 0)
198+
}
199+
142200
func (s *ExecutorSuite) TestEnvInjection(c *C) {
143201
defer restoreExecCommand()
144202
fakeExecCommand("dump-env")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy