Skip to content

Commit ae7128a

Browse files
Skip updating phpunit.xml files when .env.test exists
1 parent 27473c8 commit ae7128a

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/Configurator/EnvConfigurator.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function configure(Recipe $recipe, $vars)
2323
$this->write('Added environment variable defaults');
2424

2525
$this->configureEnvDist($recipe, $vars);
26-
$this->configurePhpUnit($recipe, $vars);
26+
if (!file_exists(getcwd().'/.env.test')) {
27+
$this->configurePhpUnit($recipe, $vars);
28+
}
2729
}
2830

2931
public function unconfigure(Recipe $recipe, $vars)
@@ -34,32 +36,34 @@ public function unconfigure(Recipe $recipe, $vars)
3436

3537
private function configureEnvDist(Recipe $recipe, $vars)
3638
{
37-
$distenv = getcwd().'/.env.dist';
38-
if (!is_file($distenv) || $this->isFileMarked($recipe, $distenv)) {
39-
return;
40-
}
41-
42-
$data = '';
43-
foreach ($vars as $key => $value) {
44-
$value = $this->evaluateValue($value);
45-
if ('#' === $key[0] && is_numeric(substr($key, 1))) {
46-
$data .= '# '.$value."\n";
39+
foreach (['.env.dist', '.env'] as $file) {
40+
$env = getcwd().'/'.$file;
41+
if (!is_file($env)) {
42+
continue;
43+
}
4744

45+
if ($this->isFileMarked($recipe, $env)) {
4846
continue;
4947
}
5048

51-
$value = $this->options->expandTargetDir($value);
52-
if (false !== strpbrk($value, " \t\n&!\"")) {
53-
$value = '"'.str_replace(['\\', '"', "\t", "\n"], ['\\\\', '\\"', '\t', '\n'], $value).'"';
49+
$data = '';
50+
foreach ($vars as $key => $value) {
51+
$value = $this->evaluateValue($value);
52+
if ('#' === $key[0] && is_numeric(substr($key, 1))) {
53+
$data .= '# '.$value."\n";
54+
55+
continue;
56+
}
57+
58+
$value = $this->options->expandTargetDir($value);
59+
if (false !== strpbrk($value, " \t\n&!\"")) {
60+
$value = '"'.str_replace(['\\', '"', "\t", "\n"], ['\\\\', '\\"', '\t', '\n'], $value).'"';
61+
}
62+
$data .= "$key=$value\n";
5463
}
55-
$data .= "$key=$value\n";
56-
}
57-
if (!file_exists(getcwd().'/.env')) {
58-
copy($distenv, getcwd().'/.env');
64+
$data = $this->markData($recipe, $data);
65+
file_put_contents($env, $data, FILE_APPEND);
5966
}
60-
$data = $this->markData($recipe, $data);
61-
file_put_contents($distenv, $data, FILE_APPEND);
62-
file_put_contents(getcwd().'/.env', $data, FILE_APPEND);
6367
}
6468

6569
private function configurePhpUnit(Recipe $recipe, $vars)

src/Flex.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ public function update(Event $event, $operations = [])
304304
if ($operations) {
305305
$this->operations = $operations;
306306
}
307+
$cwd = getcwd();
307308

308-
if (!file_exists(getcwd().'/.env') && file_exists(getcwd().'/.env.dist')) {
309+
if (!file_exists("$cwd/.env") && !file_exists("$cwd/.env.local") && file_exists("$cwd/.env.dist") && false === strpos(file_get_contents("$cwd/.env.dist"), '.env.local')) {
309310
copy(getcwd().'/.env.dist', getcwd().'/.env');
310311
}
311312

0 commit comments

Comments
 (0)