@@ -31,6 +31,14 @@ public function testDotenvAllowedValues()
31
31
$ this ->assertTrue (true );
32
32
}
33
33
34
+ public function testDotenvAllowedValuesIfPresent ()
35
+ {
36
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder );
37
+ $ dotenv ->load ();
38
+ $ dotenv ->ifPresent ('FOO ' )->allowedValues (['bar ' , 'baz ' ]);
39
+ $ this ->assertTrue (true );
40
+ }
41
+
34
42
/**
35
43
* @expectedException \Dotenv\Exception\ValidationException
36
44
* @expectedExceptionMessage One or more environment variables failed assertions: FOO is not one of [buzz, buz].
@@ -42,6 +50,17 @@ public function testDotenvProhibitedValues()
42
50
$ dotenv ->required ('FOO ' )->allowedValues (['buzz ' , 'buz ' ]);
43
51
}
44
52
53
+ /**
54
+ * @expectedException \Dotenv\Exception\ValidationException
55
+ * @expectedExceptionMessage One or more environment variables failed assertions: FOO is not one of [buzz, buz].
56
+ */
57
+ public function testDotenvProhibitedValuesIfPresent ()
58
+ {
59
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder );
60
+ $ dotenv ->load ();
61
+ $ dotenv ->ifPresent ('FOO ' )->allowedValues (['buzz ' , 'buz ' ]);
62
+ }
63
+
45
64
/**
46
65
* @expectedException \Dotenv\Exception\ValidationException
47
66
* @expectedExceptionMessage One or more environment variables failed assertions: FOOX is missing, NOPE is missing.
@@ -118,6 +137,15 @@ public function testDotenvEmptyThrowsRuntimeException()
118
137
$ dotenv ->required ('ASSERTVAR2 ' )->notEmpty ();
119
138
}
120
139
140
+ public function testDotenvEmptyWhenNotPresent ()
141
+ {
142
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'assertions.env ' );
143
+ $ dotenv ->load ();
144
+
145
+ $ dotenv ->ifPresent ('ASSERTVAR2_NO_SUCH_VARIABLE ' )->notEmpty ();
146
+ $ this ->assertTrue (true );
147
+ }
148
+
121
149
/**
122
150
* @expectedException \Dotenv\Exception\ValidationException
123
151
* @expectedExceptionMessage One or more environment variables failed assertions: ASSERTVAR9 is empty.
@@ -190,8 +218,19 @@ public function testCanValidateBooleans($boolean)
190
218
$ dotenv ->load ();
191
219
192
220
$ dotenv ->required ($ boolean )->isBoolean ();
221
+ $ this ->assertTrue (true );
222
+ }
193
223
194
- $ this ->assertTrue (true ); // anything wrong - an exception will be thrown
224
+ /**
225
+ * @dataProvider validBooleanValuesDataProvider
226
+ */
227
+ public function testCanValidateBooleansIfPresent ($ boolean )
228
+ {
229
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'booleans.env ' );
230
+ $ dotenv ->load ();
231
+
232
+ $ dotenv ->ifPresent ($ boolean )->isBoolean ();
233
+ $ this ->assertTrue (true );
195
234
}
196
235
197
236
/**
@@ -227,6 +266,19 @@ public function testCanInvalidateNonBooleans($boolean)
227
266
$ dotenv ->required ($ boolean )->isBoolean ();
228
267
}
229
268
269
+ /**
270
+ * @dataProvider invalidBooleanValuesDataProvider
271
+ * @expectedException \Dotenv\Exception\ValidationException
272
+ * @expectedExceptionMessage One or more environment variables failed assertions: INVALID_
273
+ */
274
+ public function testCanInvalidateNonBooleansIfPresent ($ boolean )
275
+ {
276
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'booleans.env ' );
277
+ $ dotenv ->load ();
278
+
279
+ $ dotenv ->ifPresent ($ boolean )->isBoolean ();
280
+ }
281
+
230
282
/**
231
283
* @expectedException \Dotenv\Exception\ValidationException
232
284
* @expectedExceptionMessage One or more environment variables failed assertions: VAR_DOES_NOT_EXIST_234782462764
@@ -239,6 +291,15 @@ public function testCanInvalidateBooleanNonExist()
239
291
$ dotenv ->required (['VAR_DOES_NOT_EXIST_234782462764 ' ])->isBoolean ();
240
292
}
241
293
294
+ public function testIfPresentBooleanNonExist ()
295
+ {
296
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'booleans.env ' );
297
+ $ dotenv ->load ();
298
+
299
+ $ dotenv ->ifPresent (['VAR_DOES_NOT_EXIST_234782462764 ' ])->isBoolean ();
300
+ $ this ->assertTrue (true );
301
+ }
302
+
242
303
/**
243
304
* List of valid integer values in fixtures/env/integers.env.
244
305
*
@@ -265,8 +326,19 @@ public function testCanValidateIntegers($integer)
265
326
$ dotenv ->load ();
266
327
267
328
$ dotenv ->required ($ integer )->isInteger ();
329
+ $ this ->assertTrue (true );
330
+ }
331
+
332
+ /**
333
+ * @dataProvider validIntegerValuesDataProvider
334
+ */
335
+ public function testCanValidateIntegersIfPresent ($ integer )
336
+ {
337
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'integers.env ' );
338
+ $ dotenv ->load ();
268
339
269
- $ this ->assertTrue (true ); // anything wrong - an exception will be thrown
340
+ $ dotenv ->ifPresent ($ integer )->isInteger ();
341
+ $ this ->assertTrue (true );
270
342
}
271
343
272
344
/**
@@ -303,6 +375,19 @@ public function testCanInvalidateNonIntegers($integer)
303
375
$ dotenv ->required ($ integer )->isInteger ();
304
376
}
305
377
378
+ /**
379
+ * @dataProvider invalidIntegerValuesDataProvider
380
+ * @expectedException \Dotenv\Exception\ValidationException
381
+ * @expectedExceptionMessage One or more environment variables failed assertions: INVALID_
382
+ */
383
+ public function testCanInvalidateNonIntegersIfExist ($ integer )
384
+ {
385
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'integers.env ' );
386
+ $ dotenv ->load ();
387
+
388
+ $ dotenv ->ifPresent ($ integer )->isInteger ();
389
+ }
390
+
306
391
/**
307
392
* @expectedException \Dotenv\Exception\ValidationException
308
393
* @expectedExceptionMessage One or more environment variables failed assertions: VAR_DOES_NOT_EXIST_234782462764
@@ -314,4 +399,13 @@ public function testCanInvalidateIntegerNonExist()
314
399
315
400
$ dotenv ->required (['VAR_DOES_NOT_EXIST_234782462764 ' ])->isInteger ();
316
401
}
402
+
403
+ public function testIfPresentIntegerNonExist ()
404
+ {
405
+ $ dotenv = Dotenv::create ($ this ->fixturesFolder , 'integers.env ' );
406
+ $ dotenv ->load ();
407
+
408
+ $ dotenv ->ifPresent (['VAR_DOES_NOT_EXIST_234782462764 ' ])->isInteger ();
409
+ $ this ->assertTrue (true );
410
+ }
317
411
}
0 commit comments