Skip to content

Commit

Permalink
workbench:install should suggest creating .env.dusk equivalent fi…
Browse files Browse the repository at this point in the history
…le when `orchestra/testbench-dusk` is installed

solved #53

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 8, 2024
1 parent 5aef887 commit c06fd27
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Orchestra\Testbench\Foundation\Console\Actions\GeneratesFile;
use Orchestra\Workbench\Workbench;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function Orchestra\Testbench\join_paths;
use function Orchestra\Testbench\package_path;
Expand All @@ -27,6 +29,20 @@ class InstallCommand extends Command
*/
public static ?string $configurationBaseFile = null;

/**
* Determine if Package also uses Testbench Dusk.
*/
protected ?bool $hasTestbenchDusk = null;

/** {@inheritDoc} */
#[\Override]
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->hasTestbenchDusk = InstalledVersions::isInstalled('orchestra/testbench-dusk');

parent::initialize($input, $output);
}

/**
* Execute the console command.
*
Expand Down Expand Up @@ -54,9 +70,7 @@ public function handle(Filesystem $filesystem)
$this->copyTestbenchConfigurationFile($filesystem, $workingPath);
$this->copyTestbenchDotEnvFile($filesystem, $workingPath);

$hasTestbenchDusk = InstalledVersions::isInstalled('orchestra/testbench-dusk');

if ($hasTestbenchDusk) {
if ($this->hasTestbenchDusk) {
$this->replaceInFile($filesystem, ["laravel: '@testbench'"], ["laravel: '@testbench-dusk'"], join_paths($workingPath, 'testbench.yaml'));
}

Expand Down Expand Up @@ -116,13 +130,27 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
return;
}

$to = join_paths($workbenchWorkingPath, $choice);
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(
filesystem: $filesystem,
components: $this->components,
force: (bool) $this->option('force'),
))->handle($from, $to);
))->handle(
$from,
join_paths($workbenchWorkingPath, $choice)
);

(new GeneratesFile(
filesystem: $filesystem,
Expand All @@ -140,14 +168,10 @@ protected function copyTestbenchDotEnvFile(Filesystem $filesystem, string $worki
*/
protected function environmentFiles(): array
{
$environmentFile = \defined('TESTBENCH_DUSK') && TESTBENCH_DUSK === true
? '.env.dusk'
: '.env';

return [
$environmentFile,
"{$environmentFile}.example",
"{$environmentFile}.dist",
'.env',
'.env.example',
'.env.dist',
];
}

Expand Down

0 comments on commit c06fd27

Please sign in to comment.