mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Fix loading of config options as env vars
This commit is contained in:
parent
6378e614b0
commit
a2f9742cfc
@ -21,7 +21,7 @@ $isTestEnv = env('APP_ENV') === 'test';
|
||||
|
||||
return (new ConfigAggregator\ConfigAggregator([
|
||||
! $isTestEnv
|
||||
? new EnvVarLoaderProvider('config/params/generated_config.php', Core\Config\EnvVars::cases())
|
||||
? new EnvVarLoaderProvider('config/params/generated_config.php', Core\Config\EnvVars::values())
|
||||
: new ConfigAggregator\ArrayProvider([]),
|
||||
Mezzio\ConfigProvider::class,
|
||||
Mezzio\Router\ConfigProvider::class,
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Config;
|
||||
|
||||
use function Functional\map;
|
||||
use function Shlinkio\Shlink\Config\env;
|
||||
|
||||
enum EnvVars: string
|
||||
@ -74,4 +75,13 @@ enum EnvVars: string
|
||||
{
|
||||
return $this->loadFromEnv() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
static $values;
|
||||
return $values ?? ($values = map(self::cases(), static fn (EnvVars $envVar) => $envVar->value));
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace ShlinkioTest\Shlink\Core\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\EnvVars;
|
||||
|
||||
use function Functional\map;
|
||||
use function putenv;
|
||||
|
||||
class EnvVarsTest extends TestCase
|
||||
@ -58,4 +59,11 @@ class EnvVarsTest extends TestCase
|
||||
yield 'DB_DRIVER without default' => [EnvVars::DB_DRIVER, null, null];
|
||||
yield 'DB_DRIVER with default' => [EnvVars::DB_DRIVER, 'foobar', 'foobar'];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function allValuesCanBeListed(): void
|
||||
{
|
||||
$expected = map(EnvVars::cases(), static fn (EnvVars $envVar) => $envVar->value);
|
||||
self::assertEquals(EnvVars::values(), $expected);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user