diff --git a/tests/EnvValidatorFactory.php b/tests/EnvValidatorFactory.php index d359a42..a38b4f1 100644 --- a/tests/EnvValidatorFactory.php +++ b/tests/EnvValidatorFactory.php @@ -14,7 +14,13 @@ public static function buildFromTestConfig(array $override = []) { $testConfig = require __DIR__ . '/config/laravel-env-validator.php'; $config = array_merge($testConfig, $override); - $validator = \Validator::make($_SERVER, $config); + + $env = []; + foreach (array_keys($config) as $variable) { + $env[$variable] = env($variable); + } + + $validator = \Validator::make($env, $config); return static::buildFromValidator($validator); } diff --git a/tests/EnvValidatorTest.php b/tests/EnvValidatorTest.php index 5b8dadc..9337da9 100644 --- a/tests/EnvValidatorTest.php +++ b/tests/EnvValidatorTest.php @@ -18,8 +18,9 @@ class EnvValidatorTest extends TestCase public function it_has_the_right_error_message() { try { - unset($_SERVER['VAR_1']); - unset($_SERVER['VAR_2']); + // unset variables + putenv('VAR_1'); + putenv('VAR_2'); $envValidator = EnvValidatorFactory::buildFromTestConfig([ 'VAR_1' => 'required', @@ -42,8 +43,8 @@ public function it_has_the_right_error_message() public function it_does_not_throw_exception_if_validation_is_met() { try { - $_SERVER['VAR_1'] = '123'; - $_SERVER['VAR_2'] = 'A'; + putenv('VAR_1=123'); + putenv('VAR_2=A'); $envValidator = EnvValidatorFactory::buildFromTestConfig([ 'VAR_1' => 'required',