Skip to content

Commit 6ffb71a

Browse files
fix
1 parent e027985 commit 6ffb71a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Command/DumpEnvCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ private function loadEnv(string $path, ?string $env): array
112112
throw new \RuntimeException('Please provide the name of the environment either by passing it as command line argument or by defining the "APP_ENV" variable in the ".env.local" file.');
113113
}
114114

115+
$config = @json_decode(file_get_contents(Factory::getComposerFile()), true);
115116
$testEnvs = $config['extra']['runtime']['test_envs'] ?? ['test'];
116117

117118
if (method_exists($dotenv, 'loadEnv')) {
118-
$config = @json_decode(file_get_contents(Factory::getComposerFile()), true);
119119
$dotenv->loadEnv($path, 'APP_ENV', 'dev', $testEnvs);
120120
} else {
121121
// fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added)

tests/Command/DumpEnvCommandTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,27 @@ public function testDoesNotRequireToSpecifyEnvArgumentWhenLocalFileIsPresent()
164164
unlink($envLocalPhp);
165165
}
166166

167+
/**
168+
* @runInSeparateProcess
169+
*/
167170
public function testLoadLocalEnvWhenTestEnvIsNotEqual()
168171
{
169172
@mkdir(FLEX_TEST_DIR);
173+
chdir(FLEX_TEST_DIR);
170174
$env = FLEX_TEST_DIR.'/.env';
171175
$envLocal = FLEX_TEST_DIR.'/.env.local';
172176
$envLocalPhp = FLEX_TEST_DIR.'/.env.local.php';
173-
$composer = __DIR__.'/../../composer.json';
177+
$composer = FLEX_TEST_DIR.'/composer.json';
178+
174179
@unlink($envLocalPhp);
175180

176181
file_put_contents($env, 'APP_ENV=dev');
177-
$envContent = <<<EOF
182+
file_put_contents($envLocal, <<<EOF
178183
APP_ENV=test
179184
APP_SECRET=abcdefgh123456789
180-
EOF;
181-
file_put_contents($envLocal, $envContent);
182-
183-
copy($composer, FLEX_TEST_DIR.'/composer-backup.json');
184-
$composerContent = @json_decode(file_get_contents($composer), true);
185-
$composerContent['extra']['runtime']['test_envs'] = [];
186-
file_put_contents($composer, json_encode($composerContent));
185+
EOF
186+
);
187+
file_put_contents(FLEX_TEST_DIR.'/composer.json', '{"extra":{"runtime":{"test_envs":[]}}}');
187188

188189
$command = $this->createCommandDumpEnv();
189190
$command->execute([
@@ -201,7 +202,7 @@ public function testLoadLocalEnvWhenTestEnvIsNotEqual()
201202
unlink($env);
202203
unlink($envLocal);
203204
unlink($envLocalPhp);
204-
copy(FLEX_TEST_DIR.'/composer-backup.json', $composer);
205+
unlink($composer);
205206
}
206207

207208
private function createCommandDumpEnv()

0 commit comments

Comments
 (0)