Skip to content

Commit

Permalink
feat: application debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyPradana committed Jul 4, 2024
1 parent 6ffc4c6 commit a92b363
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/System/Integrate/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ public function loadConfig(ConfigRepository $configs): void
$this->set('config', fn (): ConfigRepository => $configs);

// base env
$this->set('environment', $configs['ENVIRONMENT']);
$this->set('environment', $configs['APP_ENV'] ?? $configs['ENVIRONMENT']);
$this->set('app.debug', $configs['APP_DEBUG']);
// application path
$this->setAppPath($this->basePath());
$this->setModelPath($configs['MODEL_PATH']);
Expand Down Expand Up @@ -293,6 +294,7 @@ public function defaultConfigs()
'time_zone' => 'Asia/Jakarta',
'APP_KEY' => '',
'ENVIRONMENT' => 'dev',
'APP_DEBUG' => false,

'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR,
'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR,
Expand Down Expand Up @@ -818,6 +820,16 @@ public function environment()
return $this->get('environment');
}

/**
* Detect application debug enable.
*
* @return bool
*/
public function isDebugMode()
{
return $this->get('app.debug');
}

/**
* Detect application prodaction mode.
*
Expand Down
41 changes: 41 additions & 0 deletions tests/Integrate/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,46 @@ public function itCanLoadConfigFromDefault()
$app->flush();
}

/**
* @test
*/
public function itCanLoadEnvironment()
{
$app = new Application('/');

$env = $app->defaultConfigs();
$app->loadConfig(new ConfigRepository($env));
$this->assertTrue($app->isDev());
$this->assertFalse($app->isProduction());

$env['ENVIRONMENT'] = 'test';

$app->loadConfig(new ConfigRepository($env));
$this->assertEquals('test', $app->environment());

// APP_ENV
$env['APP_ENV'] = 'dev';

$app->loadConfig(new ConfigRepository($env));
$this->assertEquals('dev', $app->environment());

$app->flush();
}

/**
* @test
*/
public function itCanDetectDebugMode()
{
$app = new Application('/');

$env = $app->defaultConfigs();
$app->loadConfig(new ConfigRepository($env));
$this->assertFalse($app->isDebugMode());

$app->flush();
}

/** @test */
public function itCanNotDuplicateRegister()
{
Expand Down Expand Up @@ -247,6 +287,7 @@ private function defaultConfigs()
'time_zone' => 'Asia/Jakarta',
'APP_KEY' => '',
'ENVIRONMENT' => 'dev',
'APP_DEBUG' => false,

'COMMAND_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Commands' . DIRECTORY_SEPARATOR,
'CONTROLLER_PATH' => DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR,
Expand Down

0 comments on commit a92b363

Please sign in to comment.