From 6b26fbc289117e7b0ca625a97974faafc83b9e70 Mon Sep 17 00:00:00 2001 From: Sajed Zarinpour Nashroudkoli Date: Fri, 6 Sep 2024 16:07:10 -0400 Subject: [PATCH] set the configuration for testing for github actions (Hopefully) --- src/config/config.php | 44 ++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/config/config.php b/src/config/config.php index 17d7de9..9fe2f88 100755 --- a/src/config/config.php +++ b/src/config/config.php @@ -10,19 +10,37 @@ if (!function_exists('config')) { function config(string $key): string { - $envl = new envLoader; - $envl(__DIR__ . '/../../../../..'); + if(isset($_ENV['TEST']) && $_ENV['TEST'] == true) + { + $configs = [ + 'host' => '127.0.0.1', + 'port' => '3306', + 'database' => 'test_db', + 'user' => 'root', + 'password' => 'root', + ]; + + if (!isset($configs[$key])) + throw new \Exception('requested config key not found'); + return $configs[$key]; + } + else + { - $configs = [ - 'host' => getenv('DB_HOST') ?? '127.0.0.1', - 'port' => getenv('DB_PORT') ?? '3306', - 'database' => getenv('DB_DATABASE') ?? 'laravel', - 'user' => getenv('DB_USER') ?? 'dev', - 'password' => getenv('DB_PASSWORD') ?? 'password', - ]; - - if (empty($configs[$key])) - throw new \Exception('requested config key not found'); - return $configs[$key]; + $envl = new envLoader; + $envl(__DIR__ . '/../../../../..'); + + $configs = [ + 'host' => getenv('DB_HOST') ?? '127.0.0.1', + 'port' => getenv('DB_PORT') ?? '3306', + 'database' => getenv('DB_DATABASE') ?? 'laravel', + 'user' => getenv('DB_USER') ?? 'dev', + 'password' => getenv('DB_PASSWORD') ?? 'password', + ]; + + if (!isset($configs[$key])) + throw new \Exception('requested config key not found'); + return $configs[$key]; + } } }