66use Helhum \DotEnvConnector \Config ;
77use Helhum \DotEnvConnector \IncludeFile ;
88use PHPUnit \Framework \TestCase ;
9- use Prophecy \Prophet ;
109
1110class IncludeFileTest extends TestCase
1211{
@@ -19,6 +18,9 @@ protected function tearDown(): void
1918 }
2019 putenv ('FOO ' );
2120 putenv ('APP_ENV ' );
21+ putenv ('DOTENV_CONNECTOR_OVERRIDE ' );
22+ unset($ _ENV ['FOO ' ], $ _ENV ['APP_ENV ' ], $ _ENV ['DOTENV_CONNECTOR_OVERRIDE ' ], $ _ENV ['SYMFONY_DOTENV_VARS ' ]);
23+ unset($ _SERVER ['FOO ' ], $ _SERVER ['APP_ENV ' ], $ _SERVER ['DOTENV_CONNECTOR_OVERRIDE ' ], $ _SERVER ['SYMFONY_DOTENV_VARS ' ]);
2224 if (file_exists (__DIR__ . '/Fixtures/foo ' )) {
2325 chmod (__DIR__ . '/Fixtures/foo ' , 777 );
2426 rmdir (__DIR__ . '/Fixtures/foo ' );
@@ -28,14 +30,13 @@ protected function tearDown(): void
2830 /**
2931 * @test
3032 */
31- public function dumpDumpsFile ()
33+ public function dumpDumpsFile (): void
3234 {
3335 $ config = new Config ();
3436 $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
3537 'env-file ' => __DIR__ . '/Fixtures/env/.env ' ,
3638 'adapter ' => SymfonyDotEnv::class
3739 ]]]);
38- /** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
3940 $ loaderMock = $ this ->createMock (ClassLoader::class);
4041 $ loaderMock ->expects ($ this ->once ())->method ('register ' );
4142 $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
@@ -49,14 +50,13 @@ public function dumpDumpsFile()
4950 /**
5051 * @test
5152 */
52- public function includingFileExposesEnvVars ()
53+ public function includingFileExposesEnvVars (): void
5354 {
5455 $ config = new Config ();
5556 $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
5657 'env-file ' => __DIR__ . '/Fixtures/env/.env ' ,
5758 'adapter ' => SymfonyDotEnv::class
5859 ]]]);
59- /** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
6060 $ loaderMock = $ this ->createMock (ClassLoader::class);
6161 $ loaderMock ->expects ($ this ->once ())->method ('register ' );
6262 $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
@@ -72,15 +72,14 @@ public function includingFileExposesEnvVars()
7272 /**
7373 * @test
7474 */
75- public function includingFileDoesNothingIfEnvVarSet ()
75+ public function includingFileDoesNothingIfEnvVarSet (): void
7676 {
7777 putenv ('APP_ENV=1 ' );
7878 $ config = new Config ();
7979 $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
8080 'env-file ' => __DIR__ . '/Fixtures/env/.env ' ,
8181 'adapter ' => SymfonyDotEnv::class
8282 ]]]);
83- /** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
8483 $ loaderMock = $ this ->createMock (ClassLoader::class);
8584 $ loaderMock ->expects ($ this ->once ())->method ('register ' );
8685 $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
@@ -96,14 +95,13 @@ public function includingFileDoesNothingIfEnvVarSet()
9695 /**
9796 * @test
9897 */
99- public function includingFileDoesNothingIfEnvFileDoesNotExist ()
98+ public function includingFileDoesNothingIfEnvFileDoesNotExist (): void
10099 {
101100 $ config = new Config ();
102101 $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
103102 'env-file ' => __DIR__ . '/Fixtures/env/.no-env ' ,
104103 'adapter ' => SymfonyDotEnv::class
105104 ]]]);
106- /** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
107105 $ loaderMock = $ this ->createMock (ClassLoader::class);
108106 $ loaderMock ->expects ($ this ->once ())->method ('register ' );
109107 $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
@@ -119,14 +117,13 @@ public function includingFileDoesNothingIfEnvFileDoesNotExist()
119117 /**
120118 * @test
121119 */
122- public function dumpReturnsFalseIfFileCannotBeWritten ()
120+ public function dumpReturnsFalseIfFileCannotBeWritten (): void
123121 {
124122 $ config = new Config ();
125123 $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
126124 'env-file ' => __DIR__ . '/Fixtures/env/.no-env ' ,
127125 'adapter ' => SymfonyDotEnv::class
128126 ]]]);
129- /** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
130127 $ loaderMock = $ this ->createMock (ClassLoader::class);
131128 $ loaderMock ->expects ($ this ->once ())->method ('register ' );
132129 $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
@@ -140,42 +137,48 @@ public function dumpReturnsFalseIfFileCannotBeWritten()
140137 /**
141138 * @test
142139 */
143- public function includingFileDoesNotOverrideExistingEnvVars ()
140+ public function includingFileDoesNotOverrideExistingEnvVars (): void
144141 {
145142 putenv ('FOO=baz ' );
146- $ configProphecy = $ this ->prophesize (Config::class);
147- $ configProphecy ->get ('env-file ' )->willReturn (__DIR__ . '/Fixtures/env/.env ' );
148- $ configProphecy ->get ('adapter ' )->willReturn (SymfonyDotEnv::class);
149- $ loaderProphecy = $ this ->prophesize (ClassLoader::class);
150- $ loaderProphecy ->register ()->shouldBeCalled ();
151- $ loaderProphecy ->unregister ()->shouldBeCalled ();
143+ $ _ENV ['FOO ' ] = 'baz ' ;
144+ $ config = new Config ();
145+ $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
146+ 'env-file ' => __DIR__ . '/Fixtures/env/.env ' ,
147+ 'adapter ' => SymfonyDotEnv::class
148+ ]]]);
149+ $ loaderMock = $ this ->createMock (ClassLoader::class);
150+ $ loaderMock ->expects ($ this ->once ())->method ('register ' );
151+ $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
152152
153153 $ includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php ' ;
154- $ includeFile = new IncludeFile ($ configProphecy -> reveal () , $ loaderProphecy -> reveal () , $ includeFilePath );
154+ $ includeFile = new IncludeFile ($ config , $ loaderMock , $ includeFilePath );
155155 $ includeFile ->dump ();
156- $ this ->assertTrue ( file_exists ( $ includeFilePath) );
156+ $ this ->assertFileExists ( $ includeFilePath );
157157
158158 $ this ->assertSame ('baz ' , getenv ('FOO ' ));
159159 }
160160
161161 /**
162162 * @test
163163 */
164- public function includingFileDoesOverrideExistingEnvVars ()
164+ public function includingFileDoesOverrideExistingEnvVars (): void
165165 {
166166 putenv ('FOO=baz ' );
167+ $ _ENV ['FOO ' ] = 'baz ' ;
167168 putenv ('DOTENV_CONNECTOR_OVERRIDE=1 ' );
168- $ configProphecy = $ this ->prophesize (Config::class);
169- $ configProphecy ->get ('env-file ' )->willReturn (__DIR__ . '/Fixtures/env/.env ' );
170- $ configProphecy ->get ('adapter ' )->willReturn (SymfonyDotEnv::class);
171- $ loaderProphecy = $ this ->prophesize (ClassLoader::class);
172- $ loaderProphecy ->register ()->shouldBeCalled ();
173- $ loaderProphecy ->unregister ()->shouldBeCalled ();
169+ $ config = new Config ();
170+ $ config ->merge (['extra ' => ['helhum/dotenv-connector ' => [
171+ 'env-file ' => __DIR__ . '/Fixtures/env/.env ' ,
172+ 'adapter ' => SymfonyDotEnv::class
173+ ]]]);
174+ $ loaderMock = $ this ->createMock (ClassLoader::class);
175+ $ loaderMock ->expects ($ this ->once ())->method ('register ' );
176+ $ loaderMock ->expects ($ this ->once ())->method ('unregister ' );
174177
175178 $ includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php ' ;
176- $ includeFile = new IncludeFile ($ configProphecy -> reveal () , $ loaderProphecy -> reveal () , $ includeFilePath );
179+ $ includeFile = new IncludeFile ($ config , $ loaderMock , $ includeFilePath );
177180 $ includeFile ->dump ();
178- $ this ->assertTrue ( file_exists ( $ includeFilePath) );
181+ $ this ->assertFileExists ( $ includeFilePath );
179182
180183 $ this ->assertSame ('bar ' , getenv ('FOO ' ));
181184 }
0 commit comments