File tree Expand file tree Collapse file tree 4 files changed +60
-6
lines changed
tests/Dotenv/Repository/Adapter Expand file tree Collapse file tree 4 files changed +60
-6
lines changed Original file line number Diff line number Diff line change @@ -40,9 +40,20 @@ public static function create()
40
40
public function read (string $ name )
41
41
{
42
42
/** @var \PhpOption\Option<string> */
43
- return Option::fromArraysValue ($ _ENV , $ name )->filter (static function ($ value ) {
44
- return \is_string ($ value );
45
- });
43
+ return Option::fromArraysValue ($ _ENV , $ name )
44
+ ->map (static function ($ value ) {
45
+ if ($ value === false ) {
46
+ return 'false ' ;
47
+ }
48
+
49
+ if ($ value === true ) {
50
+ return 'true ' ;
51
+ }
52
+
53
+ return $ value ;
54
+ })->filter (static function ($ value ) {
55
+ return \is_string ($ value );
56
+ });
46
57
}
47
58
48
59
/**
Original file line number Diff line number Diff line change @@ -40,9 +40,20 @@ public static function create()
40
40
public function read (string $ name )
41
41
{
42
42
/** @var \PhpOption\Option<string> */
43
- return Option::fromArraysValue ($ _SERVER , $ name )->filter (static function ($ value ) {
44
- return \is_string ($ value );
45
- });
43
+ return Option::fromArraysValue ($ _SERVER , $ name )
44
+ ->map (static function ($ value ) {
45
+ if ($ value === false ) {
46
+ return 'false ' ;
47
+ }
48
+
49
+ if ($ value === true ) {
50
+ return 'true ' ;
51
+ }
52
+
53
+ return $ value ;
54
+ })->filter (static function ($ value ) {
55
+ return \is_string ($ value );
56
+ });
46
57
}
47
58
48
59
/**
Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ public function testGoodRead()
17
17
self ::assertSame ('foo bar baz ' , $ value ->get ());
18
18
}
19
19
20
+ public function testFalseRead ()
21
+ {
22
+ $ _ENV ['CONST_TEST ' ] = false ;
23
+ $ value = self ::createAdapter ()->read ('CONST_TEST ' );
24
+ self ::assertTrue ($ value ->isDefined ());
25
+ self ::assertSame ('false ' , $ value ->get ());
26
+ }
27
+
28
+ public function testTrueRead ()
29
+ {
30
+ $ _ENV ['CONST_TEST ' ] = true ;
31
+ $ value = self ::createAdapter ()->read ('CONST_TEST ' );
32
+ self ::assertTrue ($ value ->isDefined ());
33
+ self ::assertSame ('true ' , $ value ->get ());
34
+ }
35
+
20
36
public function testBadTypeRead ()
21
37
{
22
38
$ _ENV ['CONST_TEST ' ] = 123 ;
Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ public function testGoodRead()
17
17
self ::assertSame ('foo bar baz ' , $ value ->get ());
18
18
}
19
19
20
+ public function testFalseRead ()
21
+ {
22
+ $ _SERVER ['CONST_TEST ' ] = false ;
23
+ $ value = self ::createAdapter ()->read ('CONST_TEST ' );
24
+ self ::assertTrue ($ value ->isDefined ());
25
+ self ::assertSame ('false ' , $ value ->get ());
26
+ }
27
+
28
+ public function testTrueRead ()
29
+ {
30
+ $ _SERVER ['CONST_TEST ' ] = true ;
31
+ $ value = self ::createAdapter ()->read ('CONST_TEST ' );
32
+ self ::assertTrue ($ value ->isDefined ());
33
+ self ::assertSame ('true ' , $ value ->get ());
34
+ }
35
+
20
36
public function testBadTypeRead ()
21
37
{
22
38
$ _SERVER ['CONST_TEST ' ] = 123 ;
You can’t perform that action at this time.
0 commit comments