Skip to content

Commit

Permalink
Simplify dashboard option logic
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 11, 2023
1 parent 3fe6ad8 commit 52571f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
11 changes: 2 additions & 9 deletions packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ protected function getPortSelection(): int
return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080));
}

protected function getDashboardSelection(): ?bool
{
return $this->option('dashboard') !== null
? $this->option('dashboard') !== 'false'
: null;
}

protected function getExecutablePath(): string
{
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
Expand All @@ -79,8 +72,8 @@ protected function getEnvironmentVariables(): array
$vars = [
'HYDE_RC_REQUEST_OUTPUT' => ! $this->option('no-ansi'),
];
if ($this->getDashboardSelection() !== null) {
$vars['HYDE_RC_SERVER_DASHBOARD'] = $this->getDashboardSelection() ? 'enabled' : 'disabled';
if ($this->option('dashboard') !== null) {
$vars['HYDE_RC_SERVER_DASHBOARD'] = $this->option('dashboard') !== 'false' ? 'enabled' : 'disabled';
}

return $vars;
Expand Down
42 changes: 9 additions & 33 deletions packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,22 @@ public function test_getPortSelection_withPortOptionAndConfigOption()
$this->assertSame(8081, $this->getMock(['port' => 8081])->getPortSelection());
}

public function test_getDashboardSelection()
{
$this->assertSame(null, $this->getMock()->getDashboardSelection());
}

public function test_getDashboardSelection_withDashboardOption()
{
$this->assertSame(false, $this->getMock(['dashboard' => 'false'])->getDashboardSelection());
$this->assertSame(true, $this->getMock(['dashboard' => 'true'])->getDashboardSelection());
$this->assertSame(true, $this->getMock(['dashboard' => ''])->getDashboardSelection());
}

public function test_getDashboardSelection_withConfigOption()
{
$this->app['config']->set('hyde.server.dashboard.enabled', false);
$this->assertSame(null, $this->getMock()->getDashboardSelection());
}

public function test_getDashboardSelection_withDashboardOptionAndConfigOption()
{
$this->app['config']->set('hyde.server.dashboard.enabled', false);
$this->assertSame(true, $this->getMock(['dashboard' => 'true'])->getDashboardSelection());
}

public function test_getDashboardSelection_propagatesToEnvironmentVariables()
{
$command = $this->getMock();

$this->app['config']->set('hyde.server.dashboard.enabled', false);
$this->assertSame(false, isset($command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']));

$this->app['config']->set('hyde.server.dashboard.enabled', true);
$this->assertSame(false, isset($command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']));

$command = $this->getMock(['dashboard' => 'false']);
$this->assertSame('disabled', $command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']);

$command = $this->getMock(['dashboard' => 'true']);
$this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']);

$command = $this->getMock(['dashboard' => '']);
$this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']);

$command = $this->getMock(['dashboard' => null]);
$this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']));

$command = $this->getMock();
$this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_RC_SERVER_DASHBOARD']));
}

protected function getMock(array $options = []): ServeCommandMock
Expand All @@ -108,7 +85,6 @@ protected function getMock(array $options = []): ServeCommandMock
/**
* @method getHostSelection
* @method getPortSelection
* @method getDashboardSelection
* @method getEnvironmentVariables
*/
class ServeCommandMock extends ServeCommand
Expand Down

0 comments on commit 52571f6

Please sign in to comment.