Skip to content

Commit 0de6841

Browse files
Fixed allowedValues when not present (#420)
1 parent 8f7961f commit 0de6841

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Validator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public function allowedValues(array $choices)
133133
{
134134
return $this->assertCallback(
135135
function ($value) use ($choices) {
136+
if ($value === null) {
137+
return true;
138+
}
139+
136140
return in_array($value, $choices, true);
137141
},
138142
sprintf('is not one of [%s]', implode(', ', $choices))

tests/Dotenv/ValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public function testDotenvAllowedValuesIfPresent()
3939
$this->assertTrue(true);
4040
}
4141

42+
public function testDotenvAllowedValuesIfNotPresent()
43+
{
44+
$dotenv = Dotenv::create($this->fixturesFolder);
45+
$dotenv->load();
46+
$dotenv->ifPresent('FOOQWERTYOOOOOO')->allowedValues(['bar', 'baz']);
47+
$this->assertTrue(true);
48+
}
49+
4250
/**
4351
* @expectedException \Dotenv\Exception\ValidationException
4452
* @expectedExceptionMessage One or more environment variables failed assertions: FOO is not one of [buzz, buz].

0 commit comments

Comments
 (0)