Skip to content

Commit dbbb73a

Browse files
authored
Merge pull request #1134 from hydephp/clean-up-the-serve-command-class
Clean up the serve command class
2 parents 21c6855 + 15b89a3 commit dbbb73a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Hyde\Console\Commands;
66

7-
use Illuminate\Support\Facades\Process;
8-
use function config;
97
use Hyde\Hyde;
8+
use Hyde\Facades\Config;
9+
use Illuminate\Support\Facades\Process;
1010
use LaravelZero\Framework\Commands\Command;
1111
use function sprintf;
1212

@@ -28,8 +28,8 @@ public function handle(): int
2828
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
2929

3030
$this->runServerProcess(sprintf('php -S %s:%d %s',
31-
$this->getHostSelection() ?: 'localhost',
32-
$this->getPortSelection() ?: 8080,
31+
$this->getHostSelection(),
32+
$this->getPortSelection(),
3333
$this->getExecutablePath()
3434
));
3535

@@ -38,22 +38,23 @@ public function handle(): int
3838

3939
protected function getPortSelection(): int
4040
{
41-
return (int) ($this->option('port') ?: config('hyde.server.port', 8080));
41+
return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080));
4242
}
4343

4444
protected function getHostSelection(): string
4545
{
46-
return $this->option('host') ?: config('hyde.server.host', 'localhost');
46+
return (string) $this->option('host') ?: Config::getString('hyde.server.host', 'localhost');
4747
}
4848

4949
protected function getExecutablePath(): string
5050
{
5151
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
5252
}
5353

54+
/** @codeCoverageIgnore Until output is testable */
5455
protected function runServerProcess(string $command): void
5556
{
56-
Process::run($command, function ($type, $line) {
57+
Process::run($command, function (string $type, string $line): void {
5758
$this->output->write($line);
5859
});
5960
}

packages/framework/tests/Feature/Commands/ServeCommandTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Hyde\Hyde;
88
use Hyde\Testing\TestCase;
99
use Illuminate\Support\Facades\Process;
10+
use TypeError;
1011

1112
/**
1213
* @covers \Hyde\Console\Commands\ServeCommand
@@ -124,11 +125,24 @@ public function test_hyde_serve_command_with_host_missing_in_config_and_host_opt
124125

125126
public function test_hyde_serve_command_with_invalid_config_value()
126127
{
128+
$this->expectException(TypeError::class);
127129
config(['hyde.server.port' => 'foo']);
128130

129131
$this->artisan('serve')
130132
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
131133
->assertExitCode(0);
134+
}
135+
136+
public function test_hyde_serve_command_passes_through_process_output()
137+
{
138+
$this->markTestSkipped('Unable to access the output of the process. Assuming vendor bug for now.');
139+
140+
Process::fake(['php -S localhost:8080 {$this->binaryPath()}' => 'foo']);
141+
142+
$this->artisan('serve')
143+
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
144+
->expectsOutput('foo')
145+
->assertExitCode(0);
132146

133147
Process::assertRan("php -S localhost:8080 {$this->binaryPath()}");
134148
}

0 commit comments

Comments
 (0)