diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 9cd57f7..ae0cf2d 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -235,22 +235,30 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $content['autoload-dev']['psr-4'] = []; } + $namespacePrefix = ''; + + if ($this->components->confirm('Prefix with `Workbench` namespace?', default: true)) { + $namespacePrefix = 'Workbench\\'; + } + $namespaces = [ - 'Workbench\\App\\' => 'workbench/app/', - 'Workbench\\Database\\Factories\\' => 'workbench/database/factories/', - 'Workbench\\Database\\Seeders\\' => 'workbench/database/seeders/', + 'workbench/app/' => $namespacePrefix.'App\\', + 'workbench/database/factories/' => $namespacePrefix.'Database\\Factories\\', + 'workbench/database/seeders/' => $namespacePrefix.'Database\\Seeders\\', ]; - foreach ($namespaces as $namespace => $path) { - if (! \array_key_exists($namespace, $content['autoload-dev']['psr-4'])) { + $autoloads = array_flip($content['autoload-dev']['psr-4']); + + foreach ($namespaces as $path => $namespace) { + if (! \array_key_exists($path, $autoloads)) { $content['autoload-dev']['psr-4'][$namespace] = $path; $this->components->task(\sprintf( - 'Added [%s] for [%s] to Composer', $namespace, $path + 'Added [%s] for [%s] to Composer', $namespace, '/'.rtrim($path, '/') )); } else { $this->components->twoColumnDetail( - \sprintf('Composer already contain [%s] namespace', $namespace), + \sprintf('Composer already contains [%s] path assigned to [%s] namespace', '/'.rtrim($path, '/'), $autoloads[$path]), 'SKIPPED' ); } diff --git a/tests/Console/DevToolCommandTest.php b/tests/Console/DevToolCommandTest.php index 4534bd1..4468767 100644 --- a/tests/Console/DevToolCommandTest.php +++ b/tests/Console/DevToolCommandTest.php @@ -12,6 +12,7 @@ class DevToolCommandTest extends CommandTestCase public function it_can_run_devtool_command_with_installation(?string $answer, bool $createEnvironmentFile) { $this->artisan('workbench:devtool', ['--install' => true]) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', @@ -32,6 +33,7 @@ public function it_can_run_devtool_command_with_installation(?string $answer, bo public function it_can_run_devtool_command_with_basic_installation(?string $answer, bool $createEnvironmentFile) { $this->artisan('workbench:devtool', ['--install' => true, '--basic' => true]) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', @@ -48,6 +50,7 @@ public function it_can_run_devtool_command_with_basic_installation(?string $answ public function it_can_run_devtool_command_without_installation() { $this->artisan('workbench:devtool', ['--no-install' => true]) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); @@ -58,6 +61,7 @@ public function it_can_run_devtool_command_without_installation() public function it_can_be_installed_with_no_interaction_options() { $this->artisan('workbench:devtool', ['--no-install' => true, '--no-interaction' => true]) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); diff --git a/tests/Console/InstallCommandTest.php b/tests/Console/InstallCommandTest.php index dc3ef50..fbc1e2a 100644 --- a/tests/Console/InstallCommandTest.php +++ b/tests/Console/InstallCommandTest.php @@ -17,6 +17,7 @@ class InstallCommandTest extends CommandTestCase public function it_can_run_installation_command_with_devtool(?string $answer, bool $createEnvironmentFile) { $this->artisan('workbench:install', ['--devtool' => true]) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env',