1818class DummyExecute extends Execute
1919{
2020 public string $ returnOutput = '' ;
21+ public string $ lastCmd = '' ; // We need this for assertions against the command run.
2122
22- private function getMockProcess ($ cmd )
23+ private function getMockProcess (string $ cmd )
2324 {
2425 $ process = \Mockery::mock ('Symfony\Component\Process\Process ' );
2526 $ process ->shouldReceive (
@@ -43,22 +44,12 @@ private function getMockProcess($cmd)
4344
4445 public function run ($ cmd , ?string $ error = null ): Process
4546 {
46- if ($ cmd instanceof Process) {
47- // Get the command line from process.
48- $ cmd = $ cmd ->getCommandLine ();
49- }
50-
51- return $ this ->helper ->run ($ this ->output , $ this ->getMockProcess ($ cmd ), $ error );
47+ return $ this ->helper ->run ($ this ->output , $ this ->getMockProcess ($ this ->getCommandLine ($ cmd )), $ error );
5248 }
5349
5450 public function mustRun ($ cmd , ?string $ error = null ): Process
5551 {
56- if ($ cmd instanceof Process) {
57- // Get the command line from process.
58- $ cmd = $ cmd ->getCommandLine ();
59- }
60-
61- return $ this ->helper ->mustRun ($ this ->output , $ this ->getMockProcess ($ cmd ), $ error );
52+ return $ this ->helper ->mustRun ($ this ->output , $ this ->getMockProcess ($ this ->getCommandLine ($ cmd )), $ error );
6253 }
6354
6455 public function runAll (array $ processes ): void
@@ -73,15 +64,29 @@ public function mustRunAll(array $processes): void
7364
7465 public function passThrough (array $ commandline , ?string $ cwd = null , ?float $ timeout = null ): Process
7566 {
76- return $ this ->passThroughProcess ($ this ->getMockProcess ($ commandline ));
67+ return $ this ->getMockProcess ($ this ->getCommandLine ($ commandline ));
7768 }
7869
7970 public function passThroughProcess (Process $ process ): Process
8071 {
81- if ($ process instanceof \Mockery \MockInterface) {
82- return $ process ;
72+ return $ this ->getMockProcess ($ this ->getCommandLine ($ process ));
73+ }
74+
75+ /**
76+ * Helper function to get the command line from a Process object or array.
77+ *
78+ * @param Process|array $cmd the command to run and its arguments listed as different entities
79+ *
80+ * @return string the command to run in a shell
81+ */
82+ private function getCommandLine ($ cmd ): string
83+ {
84+ if (is_array ($ cmd )) {
85+ $ this ->lastCmd = (new Process ($ cmd ))->getCommandLine ();
86+ } else {
87+ $ this ->lastCmd = $ cmd ->getCommandLine ();
8388 }
8489
85- return $ this ->getMockProcess ( $ process -> getCommandLine ()) ;
90+ return $ this ->lastCmd ;
8691 }
8792}
0 commit comments