@@ -59,6 +59,67 @@ public static function validStrings()
59
59
];
60
60
}
61
61
62
+ /**
63
+ * @dataProvider validRealEnvValues
64
+ */
65
+ public function testGetEnvRealEnv ($ value , $ processed )
66
+ {
67
+ $ _ENV ['FOO ' ] = $ value ;
68
+
69
+ $ processor = new EnvVarProcessor (new Container ());
70
+
71
+ $ result = $ processor ->getEnv ('string ' , 'FOO ' , function () {
72
+ $ this ->fail ('Should not be called ' );
73
+ });
74
+
75
+ $ this ->assertSame ($ processed , $ result );
76
+
77
+ unset($ _ENV ['FOO ' ]);
78
+ }
79
+
80
+ public static function validRealEnvValues ()
81
+ {
82
+ return [
83
+ ['hello ' , 'hello ' ],
84
+ [true , '1 ' ],
85
+ [false , '' ],
86
+ [1 , '1 ' ],
87
+ [0 , '0 ' ],
88
+ [1.1 , '1.1 ' ],
89
+ [10 , '10 ' ],
90
+ ];
91
+ }
92
+
93
+ public function testGetEnvRealEnvInvalid ()
94
+ {
95
+ $ _ENV ['FOO ' ] = null ;
96
+ $ this ->expectException (EnvNotFoundException::class);
97
+ $ this ->expectExceptionMessage ('Environment variable not found: "FOO". ' );
98
+
99
+ $ processor = new EnvVarProcessor (new Container ());
100
+
101
+ $ processor ->getEnv ('string ' , 'FOO ' , function () {
102
+ $ this ->fail ('Should not be called ' );
103
+ });
104
+
105
+ unset($ _ENV ['FOO ' ]);
106
+ }
107
+
108
+ public function testGetEnvRealEnvNonScalar ()
109
+ {
110
+ $ _ENV ['FOO ' ] = [];
111
+ $ this ->expectException (RuntimeException::class);
112
+ $ this ->expectExceptionMessage ('Non-scalar env var "FOO" cannot be cast to "string". ' );
113
+
114
+ $ processor = new EnvVarProcessor (new Container ());
115
+
116
+ $ processor ->getEnv ('string ' , 'FOO ' , function () {
117
+ $ this ->fail ('Should not be called ' );
118
+ });
119
+
120
+ unset($ _ENV ['FOO ' ]);
121
+ }
122
+
62
123
/**
63
124
* @dataProvider validBools
64
125
*/
@@ -97,6 +158,7 @@ public static function validBools()
97
158
['true ' , true ],
98
159
['false ' , false ],
99
160
['null ' , false ],
161
+ ['' , false ],
100
162
['1 ' , true ],
101
163
['0 ' , false ],
102
164
['1.1 ' , true ],
0 commit comments