Skip to content

Commit

Permalink
Unit test opener
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 28, 2023
1 parent 8991a3d commit 2d8ffbc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2d8ffbc

Please sign in to comment.