Skip to content

Commit

Permalink
Fixing env for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasgrimm committed Feb 16, 2016
1 parent 059527e commit 40e51bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tests/EnvValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions tests/EnvValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 40e51bd

Please sign in to comment.