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()
4040 public function read (string $ name )
4141 {
4242 /** @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+ });
4657 }
4758
4859 /**
Original file line number Diff line number Diff line change @@ -40,9 +40,20 @@ public static function create()
4040 public function read (string $ name )
4141 {
4242 /** @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+ });
4657 }
4758
4859 /**
Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ public function testGoodRead()
1717 self ::assertSame ('foo bar baz ' , $ value ->get ());
1818 }
1919
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+
2036 public function testBadTypeRead ()
2137 {
2238 $ _ENV ['CONST_TEST ' ] = 123 ;
Original file line number Diff line number Diff line change @@ -17,6 +17,22 @@ public function testGoodRead()
1717 self ::assertSame ('foo bar baz ' , $ value ->get ());
1818 }
1919
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+
2036 public function testBadTypeRead ()
2137 {
2238 $ _SERVER ['CONST_TEST ' ] = 123 ;
You can’t perform that action at this time.
0 commit comments