Skip to content

Commit a60c42d

Browse files
authored
Merge pull request #1445 from hydephp/serve-command-tests
Implement process output test
2 parents a00648a + ad62dcd commit a60c42d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ protected function getExecutablePath(): string
5252
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
5353
}
5454

55-
/** @codeCoverageIgnore Until output is testable */
5655
protected function runServerProcess(string $command): void
5756
{
5857
Process::forever()->run($command, function (string $type, string $line): void {

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Hyde\Framework\Testing\Feature\Commands;
66

7+
use Closure;
78
use Hyde\Hyde;
89
use Hyde\Testing\TestCase;
910
use Illuminate\Support\Facades\Process;
@@ -135,16 +136,24 @@ public function test_hyde_serve_command_with_invalid_config_value()
135136

136137
public function test_hyde_serve_command_passes_through_process_output()
137138
{
138-
$this->markTestSkipped('Unable to access the output of the process. Assuming vendor bug for now.');
139+
Process::shouldReceive('forever')
140+
->once()
141+
->withNoArgs()
142+
->andReturnSelf();
139143

140-
Process::fake(['php -S localhost:8080 {$this->binaryPath()}' => 'foo']);
144+
Process::shouldReceive('run')
145+
->once()
146+
->withArgs(function (string $command, Closure $handle) {
147+
$handle('type', 'foo');
148+
149+
return $command === "php -S localhost:8080 {$this->binaryPath()}";
150+
})
151+
->andReturnSelf();
141152

142153
$this->artisan('serve')
143154
->expectsOutput('Starting the HydeRC server... Press Ctrl+C to stop')
144155
->expectsOutput('foo')
145156
->assertExitCode(0);
146-
147-
Process::assertRan("php -S localhost:8080 {$this->binaryPath()}");
148157
}
149158

150159
protected function binaryPath(): string

0 commit comments

Comments
 (0)