From c7bdd7ad0f054b8cd6f5c88d535404335d28a7fe Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Mon, 28 Nov 2022 05:18:05 -0600 Subject: [PATCH 1/4] Fix up the descriptor handling a pinch --- src/MockWebServer.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MockWebServer.php b/src/MockWebServer.php index 29bd45d..7d96d98 100644 --- a/src/MockWebServer.php +++ b/src/MockWebServer.php @@ -287,8 +287,17 @@ private function startServer( string $fullCmd ) { $env = null; $cwd = null; - $output = tmpfile(); - $process = proc_open($fullCmd, [fopen('php://stdin', 'r'), $output, $output], $pipes, $cwd, $env, [ + $stdin = fopen('php://stdin', 'rb'); + $output = tempnam(sys_get_temp_dir(), 'MockWebServer.stdout'); + $error = tempnam(sys_get_temp_dir(), 'MockWebServer.stderr'); + + $descriptorSpec = [ + 0 => $stdin, + 1 => [ "file", $output, "a" ], + 2 => [ "file", $error, "a" ], + ]; + + $process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [ 'suppress_errors' => false, 'bypass_shell' => true, ]); From 3de61c0b65f29c86d7cd25182b96d3571b78b8d6 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Mon, 28 Nov 2022 05:20:22 -0600 Subject: [PATCH 2/4] Fix style --- src/MockWebServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MockWebServer.php b/src/MockWebServer.php index 7d96d98..06d8070 100644 --- a/src/MockWebServer.php +++ b/src/MockWebServer.php @@ -83,7 +83,7 @@ public function start() : void { throw new Exceptions\ServerException("Failed to start server. Is something already running on port {$this->port}?"); } - register_shutdown_function(function() { + register_shutdown_function(function () { if( $this->isRunning() ) { $this->stop(); } From c963277dcfa26aac0b481c3e62e189d84cc29db3 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Mon, 28 Nov 2022 05:22:45 -0600 Subject: [PATCH 3/4] cleanup naming --- src/MockWebServer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MockWebServer.php b/src/MockWebServer.php index 06d8070..4528876 100644 --- a/src/MockWebServer.php +++ b/src/MockWebServer.php @@ -287,14 +287,14 @@ private function startServer( string $fullCmd ) { $env = null; $cwd = null; - $stdin = fopen('php://stdin', 'rb'); - $output = tempnam(sys_get_temp_dir(), 'MockWebServer.stdout'); - $error = tempnam(sys_get_temp_dir(), 'MockWebServer.stderr'); + $stdin = fopen('php://stdin', 'rb'); + $stdoutf = tempnam(sys_get_temp_dir(), 'MockWebServer.stdout'); + $stderrf = tempnam(sys_get_temp_dir(), 'MockWebServer.stderr'); $descriptorSpec = [ 0 => $stdin, - 1 => [ "file", $output, "a" ], - 2 => [ "file", $error, "a" ], + 1 => [ "file", $stdoutf, "a" ], + 2 => [ "file", $stderrf, "a" ], ]; $process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [ From 070ab75a3d1574aa69fea5947c9ea11887f73846 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Mon, 28 Nov 2022 05:23:33 -0600 Subject: [PATCH 4/4] Formatting --- src/MockWebServer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MockWebServer.php b/src/MockWebServer.php index 4528876..cfec3f8 100644 --- a/src/MockWebServer.php +++ b/src/MockWebServer.php @@ -293,8 +293,8 @@ private function startServer( string $fullCmd ) { $descriptorSpec = [ 0 => $stdin, - 1 => [ "file", $stdoutf, "a" ], - 2 => [ "file", $stderrf, "a" ], + 1 => [ 'file', $stdoutf, 'a' ], + 2 => [ 'file', $stderrf, 'a' ], ]; $process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [ @@ -306,7 +306,7 @@ private function startServer( string $fullCmd ) { return $process; } - throw new Exceptions\ServerException("Error starting server"); + throw new Exceptions\ServerException('Error starting server'); } }