diff --git a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php index 935d9793198..9e5e7069da0 100644 --- a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php @@ -5,7 +5,9 @@ namespace Hyde\Framework\Testing\Unit; use Hyde\Testing\UnitTestCase; +use Illuminate\Console\OutputStyle; use Hyde\Console\Commands\ServeCommand; +use Illuminate\Support\Facades\Process; /** * @covers \Hyde\Console\Commands\ServeCommand @@ -196,6 +198,27 @@ public function test_checkArgvForOption() $_SERVER = $serverBackup; } + public function testWithOpenArgument() + { + $output = $this->createMock(OutputStyle::class); + $output->expects($this->never())->method('writeln'); + + $command = $this->getMock(['--open' => true]); + $command->setOutput($output); + + $binary = match (PHP_OS_FAMILY) { + 'Darwin' => 'open', + 'Windows' => 'start', + default => 'xdg-open', + }; + + Process::shouldReceive('command')->once()->with("$binary http://localhost:8080")->andReturnSelf(); + Process::shouldReceive('run')->once()->andReturnSelf(); + Process::shouldReceive('failed')->once()->andReturn(false); + + $command->openInBrowser(); + } + protected function getMock(array $options = []): ServeCommandMock { return new ServeCommandMock($options);