@@ -580,7 +580,7 @@ function ($key) {
580580 $ apacheSetenv = $ this ->getFunctionMock (__NAMESPACE__ , 'apache_setenv ' );
581581 $ apacheSetenv ->expects ($ this ->any ())->willReturnCallback (
582582 function ($ key , $ value ) {
583- $ GLOBALS ['apache_test_data ' ][$ key ] = $ value ;
583+ $ GLOBALS ['apache_test_data ' ][$ key ] = ( string ) $ value ;
584584 return true ;
585585 }
586586 );
@@ -607,15 +607,15 @@ public function testToApacheSetenvSkip()
607607 $ apacheGetenv ->expects ($ this ->any ())->willReturnCallback (
608608 function ($ key ) {
609609 if (isset ($ GLOBALS ['apache_test_data ' ][$ key ])) {
610- return $ GLOBALS ['apache_test_data ' ][$ key ];
610+ return ( string ) $ GLOBALS ['apache_test_data ' ][$ key ];
611611 }
612612 return false ;
613613 }
614614 );
615615 $ apacheSetenv = $ this ->getFunctionMock (__NAMESPACE__ , 'apache_setenv ' );
616616 $ apacheSetenv ->expects ($ this ->any ())->willReturnCallback (
617617 function ($ key , $ value ) {
618- $ GLOBALS ['apache_test_data ' ][$ key ] = $ value ;
618+ $ GLOBALS ['apache_test_data ' ][$ key ] = ( string ) $ value ;
619619 return true ;
620620 }
621621 );
@@ -646,15 +646,15 @@ public function testToApacheSetenvException()
646646 $ apacheGetenv ->expects ($ this ->any ())->willReturnCallback (
647647 function ($ key ) {
648648 if (isset ($ GLOBALS ['apache_test_data ' ][$ key ])) {
649- return $ GLOBALS ['apache_test_data ' ][$ key ];
649+ return ( string ) $ GLOBALS ['apache_test_data ' ][$ key ];
650650 }
651651 return false ;
652652 }
653653 );
654654 $ apacheSetenv = $ this ->getFunctionMock (__NAMESPACE__ , 'apache_setenv ' );
655655 $ apacheSetenv ->expects ($ this ->any ())->willReturnCallback (
656656 function ($ key , $ value ) {
657- $ GLOBALS ['apache_test_data ' ][$ key ] = $ value ;
657+ $ GLOBALS ['apache_test_data ' ][$ key ] = ( string ) $ value ;
658658 return true ;
659659 }
660660 );
@@ -664,6 +664,48 @@ function ($key, $value) {
664664 $ this ->Loader ->apacheSetenv (false );
665665 }
666666
667+
668+ /**
669+ * @covers \josegonzalez\Dotenv\Loader::putenv
670+ */
671+ public function testToApacheSetenvPreserveZeros ()
672+ {
673+ if (version_compare (PHP_VERSION , '7.0 ' , '< ' )) {
674+ $ this ->markTestSkipped ('Unable to mock bare php functions ' );
675+ }
676+
677+ $ apacheGetenv = $ this ->getFunctionMock (__NAMESPACE__ , 'apache_getenv ' );
678+ $ apacheGetenv ->expects ($ this ->any ())->willReturnCallback (
679+ function ($ key ) {
680+ if (isset ($ GLOBALS ['apache_test_data ' ][$ key ])) {
681+ return (string )$ GLOBALS ['apache_test_data ' ][$ key ];
682+ }
683+ return false ;
684+ }
685+ );
686+ $ apacheSetenv = $ this ->getFunctionMock (__NAMESPACE__ , 'apache_setenv ' );
687+ $ apacheSetenv ->expects ($ this ->any ())->willReturnCallback (
688+ function ($ key , $ value ) {
689+ $ GLOBALS ['apache_test_data ' ][$ key ] = (string )$ value ;
690+ return true ;
691+ }
692+ );
693+
694+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_0.env ' );
695+ $ this ->Loader ->parse ();
696+ $ this ->Loader ->apacheSetenv (false );
697+
698+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_1.env ' );
699+ $ this ->Loader ->parse ();
700+ $ this ->Loader ->skipExisting ('apacheSetenv ' );
701+ $ this ->Loader ->apacheSetenv (false );
702+
703+ $ this ->assertEquals ('0 ' , apache_getenv ('Z_NUMBER ' ));
704+ $ this ->assertEquals ('' , apache_getenv ('Z_BOOL ' ));
705+ $ this ->assertEquals ('' , apache_getenv ('Z_STRING ' ));
706+ $ this ->assertEquals ('' , apache_getenv ('Z_NULLABLE ' ));
707+ }
708+
667709 /**
668710 * @covers \josegonzalez\Dotenv\Loader::define
669711 */
@@ -746,6 +788,26 @@ public function testToPutenvException()
746788 $ this ->Loader ->putenv (false );
747789 }
748790
791+ /**
792+ * @covers \josegonzalez\Dotenv\Loader::putenv
793+ */
794+ public function testToPutenvPreserveZeros ()
795+ {
796+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_0.env ' );
797+ $ this ->Loader ->parse ();
798+ $ this ->Loader ->putenv (false );
799+
800+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_1.env ' );
801+ $ this ->Loader ->parse ();
802+ $ this ->Loader ->skipExisting ('putenv ' );
803+ $ this ->Loader ->putenv (false );
804+
805+ $ this ->assertEquals ('0 ' , getenv ('Z_NUMBER ' ));
806+ $ this ->assertEquals ('' , getenv ('Z_BOOL ' ));
807+ $ this ->assertEquals ('' , getenv ('Z_STRING ' ));
808+ $ this ->assertEquals ('' , getenv ('Z_NULLABLE ' ));
809+ }
810+
749811 /**
750812 * @covers \josegonzalez\Dotenv\Loader::toEnv
751813 */
@@ -788,6 +850,26 @@ public function testToEnvException()
788850 $ this ->Loader ->toEnv (false );
789851 }
790852
853+ /**
854+ * @covers \josegonzalez\Dotenv\Loader::toEnv
855+ */
856+ public function testToEnvPreserveZeros ()
857+ {
858+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_0.env ' );
859+ $ this ->Loader ->parse ();
860+ $ this ->Loader ->toEnv (false );
861+
862+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_1.env ' );
863+ $ this ->Loader ->parse ();
864+ $ this ->Loader ->skipExisting ('toEnv ' );
865+ $ this ->Loader ->toEnv (false );
866+
867+ $ this ->assertEquals (0 , $ _ENV ['Z_NUMBER ' ]);
868+ $ this ->assertEquals (false , $ _ENV ['Z_BOOL ' ]);
869+ $ this ->assertEquals ('' , $ _ENV ['Z_STRING ' ]);
870+ $ this ->assertEquals (null , $ _ENV ['Z_NULLABLE ' ]);
871+ }
872+
791873 /**
792874 * @covers \josegonzalez\Dotenv\Loader::toServer
793875 */
@@ -830,6 +912,26 @@ public function testToServerException()
830912 $ this ->Loader ->toServer (false );
831913 }
832914
915+ /**
916+ * @covers \josegonzalez\Dotenv\Loader::toServer
917+ */
918+ public function testToServerPreserveZeros ()
919+ {
920+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_0.env ' );
921+ $ this ->Loader ->parse ();
922+ $ this ->Loader ->toServer (false );
923+
924+ $ this ->Loader ->setFilepaths ($ this ->fixturePath . 'zero_test_1.env ' );
925+ $ this ->Loader ->parse ();
926+ $ this ->Loader ->skipExisting ('toServer ' );
927+ $ this ->Loader ->toServer (false );
928+
929+ $ this ->assertEquals (0 , $ _SERVER ['Z_NUMBER ' ]);
930+ $ this ->assertEquals (false , $ _SERVER ['Z_BOOL ' ]);
931+ $ this ->assertEquals ('' , $ _SERVER ['Z_STRING ' ]);
932+ $ this ->assertEquals (null , $ _SERVER ['Z_NULLABLE ' ]);
933+ }
934+
833935 /**
834936 * @covers \josegonzalez\Dotenv\Loader::skipped
835937 * @covers \josegonzalez\Dotenv\Loader::skipExisting
0 commit comments