Skip to content

Commit

Permalink
Refactor to use testable Illuminate process
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 28, 2023
1 parent 3fc283d commit 5e40f9b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -152,13 +151,13 @@ protected function openInBrowser(): void
default => null
};

Check warning on line 152 in packages/framework/src/Console/Commands/ServeCommand.php

View check run for this annotation

Codecov / codecov/patch

packages/framework/src/Console/Commands/ServeCommand.php#L147-L152

Added lines #L147 - L152 were not covered by tests

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();

Check warning on line 154 in packages/framework/src/Console/Commands/ServeCommand.php

View check run for this annotation

Codecov / codecov/patch

packages/framework/src/Console/Commands/ServeCommand.php#L154

Added line #L154 was not covered by tests

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())));

Check warning on line 158 in packages/framework/src/Console/Commands/ServeCommand.php

View check run for this annotation

Codecov / codecov/patch

packages/framework/src/Console/Commands/ServeCommand.php#L156-L158

Added lines #L156 - L158 were not covered by tests
}

$this->newLine();

Check warning on line 161 in packages/framework/src/Console/Commands/ServeCommand.php

View check run for this annotation

Codecov / codecov/patch

packages/framework/src/Console/Commands/ServeCommand.php#L161

Added line #L161 was not covered by tests
}
}

0 comments on commit 5e40f9b

Please sign in to comment.