Fix tests not properly unsetting env vars

This commit is contained in:
Alejandro Celaya 2024-10-13 12:32:59 +02:00
parent 14ba9fd6a4
commit 1ec950ee1e
2 changed files with 7 additions and 8 deletions

View File

@ -8,7 +8,6 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode;
use function date_default_timezone_get; use function date_default_timezone_get;
use function file_get_contents; use function file_get_contents;
use function getenv;
use function is_file; use function is_file;
use function Shlinkio\Shlink\Config\env; use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Config\parseEnvVar; use function Shlinkio\Shlink\Config\parseEnvVar;

View File

@ -25,9 +25,9 @@ class EnvVarsTest extends TestCase
protected function tearDown(): void protected function tearDown(): void
{ {
putenv(EnvVars::BASE_PATH->value . '='); putenv(EnvVars::BASE_PATH->value);
putenv(EnvVars::DB_NAME->value . '='); putenv(EnvVars::DB_NAME->value);
putenv(EnvVars::DB_PASSWORD->value . '_FILE='); putenv(EnvVars::DB_PASSWORD->value . '_FILE');
} }
#[Test, DataProvider('provideExistingEnvVars')] #[Test, DataProvider('provideExistingEnvVars')]
@ -38,9 +38,9 @@ class EnvVarsTest extends TestCase
public static function provideExistingEnvVars(): iterable public static function provideExistingEnvVars(): iterable
{ {
yield 'DB_NAME' => [EnvVars::DB_NAME, true]; yield 'DB_NAME (is set)' => [EnvVars::DB_NAME, true];
yield 'BASE_PATH' => [EnvVars::BASE_PATH, true]; yield 'BASE_PATH (is set)' => [EnvVars::BASE_PATH, true];
yield 'DB_DRIVER' => [EnvVars::DB_DRIVER, false]; yield 'DB_DRIVER (has default)' => [EnvVars::DB_DRIVER, true];
yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false]; yield 'DEFAULT_REGULAR_404_REDIRECT' => [EnvVars::DEFAULT_REGULAR_404_REDIRECT, false];
} }
@ -75,7 +75,7 @@ class EnvVarsTest extends TestCase
try { try {
self::assertEquals($expectedPort, EnvVars::DB_PORT->loadFromEnv()); self::assertEquals($expectedPort, EnvVars::DB_PORT->loadFromEnv());
} finally { } finally {
putenv(EnvVars::DB_DRIVER->value . '='); putenv(EnvVars::DB_DRIVER->value);
} }
} }
} }