From 3fe6ad8ecd1d5f7319c5f934d9262b772cb6d13d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 11 Nov 2023 15:42:01 +0100 Subject: [PATCH] Open up logic for testing --- .../Foundation/Internal/LoadConfiguration.php | 15 ++++++++---- .../tests/Unit/LoadConfigurationTest.php | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/framework/src/Foundation/Internal/LoadConfiguration.php b/packages/framework/src/Foundation/Internal/LoadConfiguration.php index db1f13f5895..7c1243762ca 100644 --- a/packages/framework/src/Foundation/Internal/LoadConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadConfiguration.php @@ -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); + } } diff --git a/packages/framework/tests/Unit/LoadConfigurationTest.php b/packages/framework/tests/Unit/LoadConfigurationTest.php index d1125608255..f37e13f0c26 100644 --- a/packages/framework/tests/Unit/LoadConfigurationTest.php +++ b/packages/framework/tests/Unit/LoadConfigurationTest.php @@ -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]; + } }