Skip to content

Commit

Permalink
Test opening with paths
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 27, 2024
1 parent c4224b6 commit 30c75de
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,70 @@ protected function openInBrowser(string $path = '/'): void
$this->assertTrue($command->openInBrowserCalled);
}

public function testWithOpenArgumentWhenString()
{
HydeKernel::setInstance(new HydeKernel());

$command = new class(['open' => '']) extends ServeCommandMock
{
public bool $openInBrowserCalled = false;

// Void unrelated methods
protected function configureOutput(): void
{
}

protected function printStartMessage(): void
{
}

protected function runServerProcess(string $command): void
{
}

protected function openInBrowser(string $path = '/'): void
{
$this->openInBrowserCalled = true;
}
};

$command->safeHandle();

$this->assertTrue($command->openInBrowserCalled);
}

public function testWithOpenArgumentWhenPath()
{
HydeKernel::setInstance(new HydeKernel());

$command = new class(['open' => 'dashboard']) extends ServeCommandMock
{
public string $openInBrowserPath = '';

// Void unrelated methods
protected function configureOutput(): void
{
}

protected function printStartMessage(): void
{
}

protected function runServerProcess(string $command): void
{
}

protected function openInBrowser(string $path = '/'): void
{
$this->openInBrowserPath = $path;
}
};

$command->safeHandle();

$this->assertSame('dashboard', $command->openInBrowserPath);
}

public function testOpenInBrowser()
{
$output = $this->createMock(OutputStyle::class);
Expand All @@ -262,6 +326,31 @@ public function testOpenInBrowser()
$command->openInBrowser();
}

public function testOpenInBrowserWithPath()
{
Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/dashboard")->andReturnSelf();
Process::shouldReceive('run')->once()->andReturnSelf();
Process::shouldReceive('failed')->once()->andReturn(false);

$this->getMock()->openInBrowser('dashboard');
}

public function testOpenInBrowserWithPathNormalizesPaths()
{
Process::shouldReceive('run')->andReturnSelf();
Process::shouldReceive('failed')->andReturn(false);

Process::shouldReceive('command')->times(3)->with("{$this->getTestRunnerBinary()} http://localhost:8080")->andReturnSelf();
Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/dashboard")->andReturnSelf();
Process::shouldReceive('command')->once()->with("{$this->getTestRunnerBinary()} http://localhost:8080/foo/bar")->andReturnSelf();

$this->getMock()->openInBrowser('');
$this->getMock()->openInBrowser('/');
$this->getMock()->openInBrowser('//');
$this->getMock()->openInBrowser('dashboard/');
$this->getMock()->openInBrowser('foo/bar/');
}

public function testOpenInBrowserThatFails()
{
$output = Mockery::mock(OutputStyle::class);
Expand Down

0 comments on commit 30c75de

Please sign in to comment.