diff --git a/config/config.php b/config/config.php index 201c1a17..6c38707d 100644 --- a/config/config.php +++ b/config/config.php @@ -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, diff --git a/module/Core/src/Config/EnvVars.php b/module/Core/src/Config/EnvVars.php index 8f8689be..ae93e4da 100644 --- a/module/Core/src/Config/EnvVars.php +++ b/module/Core/src/Config/EnvVars.php @@ -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)); + } } diff --git a/module/Core/test/Config/EnvVarsTest.php b/module/Core/test/Config/EnvVarsTest.php index 6d4b1394..ff4878de 100644 --- a/module/Core/test/Config/EnvVarsTest.php +++ b/module/Core/test/Config/EnvVarsTest.php @@ -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); + } }