Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 9, 2024
1 parent 15af2dd commit 8333d21
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki

$from = $this->laravel->basePath('.env.example');

if (! $filesystem->exists($from)) {
if (! $filesystem->isFile($this->laravel->basePath('.env.example'))) {
return;
}

$choices = Collection::make($this->environmentFiles())
->reject(static fn ($file) => $filesystem->exists(join_paths($workbenchWorkingPath, $file)))
->reject(static fn ($file) => $filesystem->isFile(join_paths($workbenchWorkingPath, $file)))
->values()
->prepend('Skip exporting .env')
->all();
Expand All @@ -121,26 +121,19 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
return;
}

/** @var string|null $choice */
$choice = $this->components->choice("Export '.env' file as?", $choices);
/** @var string|null $targetEnvironmentFile */
$targetEnvironmentFile = $this->components->choice("Export '.env' file as?", $choices);

if (\is_null($choice) || $choice === 'Skip exporting .env') {
if (\is_null($targetEnvironmentFile) || $targetEnvironmentFile === 'Skip exporting .env') {
return;
}

$filesystem->ensureDirectoryExists($workbenchWorkingPath);

$this->generateSeparateEnvironmentFileForTestbenchDusk($filesystem, $workbenchWorkingPath, $targetEnvironmentFile);

if ($this->hasTestbenchDusk === true) {
if ($this->components->confirm('Create separate environment file for Testbench Dusk?', false)) {
(new GeneratesFile(
filesystem: $filesystem,
components: $this->components,
force: (bool) $this->option('force'),
))->handle(
$from,
join_paths($workbenchWorkingPath, str_replace('.env', '.env.dusk', $choice))
);
}

}

(new GeneratesFile(
Expand All @@ -149,7 +142,7 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
force: (bool) $this->option('force'),
))->handle(
$from,
join_paths($workbenchWorkingPath, $choice)
join_paths($workbenchWorkingPath, $targetEnvironmentFile)
);

(new GeneratesFile(
Expand All @@ -161,6 +154,29 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
);
}

/**
* Generate separate `.env.dusk` equivalent for Testbench Dusk.
*
* @codeCoverageIgnore
*/
protected function generateSeparateEnvironmentFileForTestbenchDusk(Filesystem $filesystem, string $workbenchWorkingPath, string $targetEnvironmentFile): void
{
if ($this->hasTestbenchDusk === false) {
return;
}

if ($this->components->confirm('Create separate environment file for Testbench Dusk?', false)) {
(new GeneratesFile(
filesystem: $filesystem,
components: $this->components,
force: (bool) $this->option('force'),
))->handle(
$this->laravel->basePath('.env.example'),
join_paths($workbenchWorkingPath, str_replace('.env', '.env.dusk', $targetEnvironmentFile))
);
}
}

/**
* Get possible environment files.
*
Expand Down

0 comments on commit 8333d21

Please sign in to comment.