Skip to content

Commit 93e0a1c

Browse files
committed
test can invalidate non boolean values
1 parent 406419b commit 93e0a1c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/Dotenv/ValidatorBooleanTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,36 @@ public function testCanValidateBooleans($boolean)
6060

6161
$this->assertTrue(true); // anything wrong - an exception will be thrown
6262
}
63+
64+
/**
65+
* List of non-boolean values in fixtures/env/booleans.env
66+
*
67+
* @return array
68+
*/
69+
public function invalidBooleanValuesDataProvider()
70+
{
71+
return [
72+
['INVALID_SOMETHING'],
73+
['INVALID_EMPTY'],
74+
['INVALID_EMPTY_STRING'],
75+
['INVALID_NULL'],
76+
['INVALID_NUMBER_POSITIVE'],
77+
['INVALID_NUMBER_NEGATIVE'],
78+
['INVALID_MINUS'],
79+
['INVALID_TILDA'],
80+
['INVALID_EXCLAMATION'],
81+
];
82+
}
83+
84+
/**
85+
* @dataProvider invalidBooleanValuesDataProvider
86+
* @expectedException Dotenv\Exception\ValidationException
87+
*/
88+
public function testCanInvalidateNonBooleans($boolean)
89+
{
90+
$dotenv = new Dotenv($this->fixturesFolder, 'booleans.env');
91+
$dotenv->load();
92+
93+
$dotenv->required($boolean)->isBoolean();
94+
}
6395
}

tests/fixtures/env/booleans.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ VALID_YESNO_UPPERCASE_TRUE=YES
2121
VALID_YESNO_UPPERCASE_FALSE=NO
2222
VALID_YESNO_MIXEDCASE_TRUE=Yes
2323
VALID_YESNO_MIXEDCASE_FALSE=No
24+
25+
INVALID_SOMETHING=something
26+
INVALID_EMPTY=
27+
INVALID_EMPTY_STRING=""
28+
INVALID_NULL=null
29+
INVALID_NUMBER_POSITIVE=2
30+
INVALID_NUMBER_NEGATIVE=-2
31+
INVALID_MINUS=-
32+
INVALID_TILDA=~
33+
INVALID_EXCLAMATION=!

0 commit comments

Comments
 (0)