From 5e40f9b2473794996d09c22c1b1ceaa64b50909a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 28 Nov 2023 12:26:22 +0100 Subject: [PATCH] Refactor to use testable Illuminate process --- .../src/Console/Commands/ServeCommand.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Console/Commands/ServeCommand.php b/packages/framework/src/Console/Commands/ServeCommand.php index 57a56059e23..fa92220cda9 100644 --- a/packages/framework/src/Console/Commands/ServeCommand.php +++ b/packages/framework/src/Console/Commands/ServeCommand.php @@ -12,10 +12,9 @@ use Hyde\Console\Concerns\Command; use Hyde\RealtimeCompiler\ConsoleOutput; use Illuminate\Support\Facades\Process; -use Symfony\Component\Process\Process as SymfonyProcess; -use Symfony\Component\Process\Exception\ProcessFailedException; use function sprintf; +use function str_replace; use function class_exists; /** @@ -152,13 +151,13 @@ protected function openInBrowser(): void default => null }; - try { - SymfonyProcess::fromShellCommandline(sprintf('%s http://%s:%d', $command, $this->getHostSelection(), $this->getPortSelection()))->mustRun(); - } catch (ProcessFailedException $exception) { - $this->warn("Unable to open the site preview in the browser on your system.\n"); - if ($this->output->isVerbose()) { - $this->line($exception->getMessage()); - } + $process = Process::command(sprintf('%s http://%s:%d', $command, $this->getHostSelection(), $this->getPortSelection()))->run(); + + if ($process->failed()) { + $this->warn('Unable to open the site preview in the browser on your system:'); + $this->line(sprintf(' %s', str_replace("\n", "\n ", $process->errorOutput()))); } + + $this->newLine(); } }