Skip to content

Commit

Permalink
Open up logic for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 11, 2023
1 parent b3f46e5 commit 3fe6ad8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/framework/src/Foundation/Internal/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ private function loadRuntimeConfiguration(Application $app, RepositoryContract $
if (in_array('--no-api', $_SERVER['argv'], true)) {
$repository->set('hyde.api_calls', false);
}
} else {
// Check if HYDE_RC_SERVER_DASHBOARD environment variable is set, and if so, set the config value accordingly.
if (getenv('HYDE_RC_SERVER_DASHBOARD') !== false) {
$repository->set('hyde.server.dashboard.enabled', getenv('HYDE_RC_SERVER_DASHBOARD') === 'enabled');
}
}

// Check if HYDE_RC_SERVER_DASHBOARD environment variable is set, and if so, set the config value accordingly.
if ($this->getEnv('HYDE_RC_SERVER_DASHBOARD') !== false) {
$repository->set('hyde.server.dashboard.enabled', $this->getEnv('HYDE_RC_SERVER_DASHBOARD') === 'enabled');
}
}
}

protected function getEnv(string $name): string|false
{
return getenv($name);
}
}
24 changes: 24 additions & 0 deletions packages/framework/tests/Unit/LoadConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,28 @@ public function testItLoadsRuntimeConfiguration()
$this->assertFalse(config('hyde.pretty_urls'));
$this->assertNull(config('hyde.api_calls'));
}

public function testItLoadsRealtimeCompilerEnvironmentConfiguration()
{
(new LoadConfigurationEnvironmentTestClass(['HYDE_RC_SERVER_DASHBOARD' => 'enabled']))->bootstrap(new Application(getcwd()));
$this->assertTrue(config('hyde.server.dashboard.enabled'));

(new LoadConfigurationEnvironmentTestClass(['HYDE_RC_SERVER_DASHBOARD' => 'disabled']))->bootstrap(new Application(getcwd()));
$this->assertFalse(config('hyde.server.dashboard.enabled'));
}
}

class LoadConfigurationEnvironmentTestClass extends LoadConfiguration
{
protected array $env;

public function __construct(array $env)
{
$this->env = $env;
}

protected function getEnv(string $name): string|false
{
return $this->env[$name];
}
}

0 comments on commit 3fe6ad8

Please sign in to comment.