Skip to content

Commit

Permalink
Init now can only return false when failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Nov 8, 2023
1 parent 64db731 commit 0e02dc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Ease/Shared.php
Expand Up @@ -61,8 +61,11 @@ class Shared extends Atom
*
* @param array $configKeys
* @param string $envFile
* @param boolean $exit do exit(1) when unsuccessful ?
*
* @return boolean Configuration success
*/
public static function init($configKeys = [], $envFile = '')
public static function init($configKeys = [], $envFile = '', $exit = true)
{
if (empty($envFile) === false) {
if (file_exists($envFile)) {
Expand All @@ -72,7 +75,7 @@ public static function init($configKeys = [], $envFile = '')
}
}
$configured = true;
if (array_key_exists('DB_CONNECTION', $configKeys) && preg_match('/^sqlite/', self::cfg('DB_CONNECTION', ''))) {
if ((array_search('DB_CONNECTION', $configKeys) !== false) && preg_match('/^sqlite/', self::cfg('DB_CONNECTION', ''))) {
unset($configKeys['DB_PASSWORD']);
unset($configKeys['DB_USERNAME']);
unset($configKeys['DB_HOST']);
Expand All @@ -84,9 +87,10 @@ public static function init($configKeys = [], $envFile = '')
$configured = false;
}
}
if ($configured === false) {
if ($exit && ($configured === false)) {
exit(1);
}
return $configured;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/src/Ease/SharedTest.php
Expand Up @@ -126,6 +126,15 @@ public function testLoadConfig()
$this->object->loadConfig('tests/Bootstrap.php', true);
}

/**
* @covers Ease\Shared::init
*/
public function testInit()
{
putenv('DB_CONNECTION=sqlite3');
$this->assertTrue(\Ease\Shared::init(['DB_CONNECTION'], null, false));
}

/**
* @covers Ease\Shared::saveStatusMessages
*/
Expand Down

0 comments on commit 0e02dc2

Please sign in to comment.