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 8333d21 commit bc21766
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki

$choices = Collection::make($this->environmentFiles())
->reject(static fn ($file) => $filesystem->isFile(join_paths($workbenchWorkingPath, $file)))
->values()
->prepend('Skip exporting .env')
->all();
->values();

if (! $this->option('force') && empty($choices)) {
if (! $this->option('force') && $choices->isEmpty()) {
$this->components->twoColumnDetail(
'File [.env] already exists', '<fg=yellow;options=bold>SKIPPED</>'
);
Expand All @@ -122,7 +120,10 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
}

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

if (\is_null($targetEnvironmentFile) || $targetEnvironmentFile === 'Skip exporting .env') {
return;
Expand All @@ -132,10 +133,6 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki

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

if ($this->hasTestbenchDusk === true) {

}

(new GeneratesFile(
filesystem: $filesystem,
components: $this->components,
Expand Down
1 change: 1 addition & 0 deletions tests/Console/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ protected function assertFromEnvironmentFileDataProviders(?string $answer, bool
*/
public static function environmentFileDataProviders()
{
yield [null, false];
yield ['Skip exporting .env', false];
yield ['.env', true];
yield ['.env.example', true];
Expand Down
26 changes: 23 additions & 3 deletions tests/Console/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orchestra\Workbench\Tests\Console;

use Illuminate\Filesystem\Filesystem;
use Orchestra\Testbench\Foundation\Config;

use function Orchestra\Testbench\default_skeleton_path;
Expand All @@ -18,7 +19,7 @@ public function it_can_run_installation_command_with_devtool(?string $answer, bo
{
$workingPath = static::stubWorkingPath();

$this->artisan('workbench:install', ['--devtool' => true, '--no-interaction' => true])
$this->artisan('workbench:install', ['--devtool' => true])
->expectsChoice("Export '.env' file as?", $answer, [
'Skip exporting .env',
'.env',
Expand Down Expand Up @@ -58,7 +59,7 @@ public function it_can_run_installation_command_without_devtool(?string $answer,
{
$workingPath = static::stubWorkingPath();

$this->artisan('workbench:install', ['--no-devtool' => true, '--no-interaction' => true])
$this->artisan('workbench:install', ['--no-devtool' => true])
->expectsChoice("Export '.env' file as?", $answer, [
'Skip exporting .env',
'.env',
Expand Down Expand Up @@ -98,7 +99,7 @@ public function it_can_run_basic_installation_command_without_devtool(?string $a
{
$workingPath = static::stubWorkingPath();

$this->artisan('workbench:install', ['--basic' => true, '--no-devtool' => true, '--no-interaction' => true])
$this->artisan('workbench:install', ['--basic' => true, '--no-devtool' => true])
->expectsChoice("Export '.env' file as?", $answer, [
'Skip exporting .env',
'.env',
Expand All @@ -120,4 +121,23 @@ public function it_can_run_basic_installation_command_without_devtool(?string $a
$this->assertExecuteInstallWithoutDevTool();
$this->assertFromEnvironmentFileDataProviders($answer, $createEnvironmentFile);
}

/**
* @test
*/
public function it_can_ignore_generating_environment_file_if_it_already_exists()
{
$filesystem = new Filesystem;
$workingPath = static::stubWorkingPath();

$filesystem->ensureDirectoryExists(join_paths($workingPath, 'workbench'));
collect(['.env', '.env.example', '.env.dist'])
->each(function ($env) use ($filesystem, $workingPath) {
$filesystem->put(join_paths($workingPath, 'workbench', $env), '');
});

$this->artisan('workbench:install', ['--basic' => true, '--no-devtool' => true])
->expectsOutputToContain('File [.env] already exists')
->assertSuccessful();
}
}

0 comments on commit bc21766

Please sign in to comment.