From 1ec950ee1e2ad29e825a3ec662e86035c80b5cb3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 13 Oct 2024 12:32:59 +0200 Subject: [PATCH] Fix tests not properly unsetting env vars --- module/Core/src/Config/EnvVars.php | 1 - module/Core/test/Config/EnvVarsTest.php | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/module/Core/src/Config/EnvVars.php b/module/Core/src/Config/EnvVars.php index d9fb1442..d1352f18 100644 --- a/module/Core/src/Config/EnvVars.php +++ b/module/Core/src/Config/EnvVars.php @@ -8,7 +8,6 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; use function date_default_timezone_get; use function file_get_contents; -use function getenv; use function is_file; use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\parseEnvVar; diff --git a/module/Core/test/Config/EnvVarsTest.php b/module/Core/test/Config/EnvVarsTest.php index 5af82c58..c2d8f8e7 100644 --- a/module/Core/test/Config/EnvVarsTest.php +++ b/module/Core/test/Config/EnvVarsTest.php @@ -25,9 +25,9 @@ class EnvVarsTest extends TestCase protected function tearDown(): void { - putenv(EnvVars::BASE_PATH->value . '='); - putenv(EnvVars::DB_NAME->value . '='); - putenv(EnvVars::DB_PASSWORD->value . '_FILE='); + putenv(EnvVars::BASE_PATH->value); + putenv(EnvVars::DB_NAME->value); + putenv(EnvVars::DB_PASSWORD->value . '_FILE'); } #[Test, DataProvider('provideExistingEnvVars')] @@ -38,9 +38,9 @@ class EnvVarsTest extends TestCase public static function provideExistingEnvVars(): iterable { - yield 'DB_NAME' => [EnvVars::DB_NAME, true]; - yield 'BASE_PATH' => [EnvVars::BASE_PATH, true]; - yield 'DB_DRIVER' => [EnvVars::DB_DRIVER, false]; + yield 'DB_NAME (is set)' => [EnvVars::DB_NAME, true]; + yield 'BASE_PATH (is set)' => [EnvVars::BASE_PATH, true]; + yield 'DB_DRIVER (has default)' => [EnvVars::DB_DRIVER, true]; yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false]; } @@ -75,7 +75,7 @@ class EnvVarsTest extends TestCase try { self::assertEquals($expectedPort, EnvVars::DB_PORT->loadFromEnv()); } finally { - putenv(EnvVars::DB_DRIVER->value . '='); + putenv(EnvVars::DB_DRIVER->value); } } }