diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 91e1ee2..33a4af1 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -237,22 +237,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 74d6e95..470ddca 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', @@ -29,6 +30,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', @@ -45,6 +47,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(); @@ -55,6 +58,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 6c9ca9a..919f411 100644 --- a/tests/Console/InstallCommandTest.php +++ b/tests/Console/InstallCommandTest.php @@ -16,6 +16,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', diff --git a/tests/Console/stubs/composer.json b/tests/Console/stubs/composer.json index 7919fe8..4e83d26 100644 --- a/tests/Console/stubs/composer.json +++ b/tests/Console/stubs/composer.json @@ -1,9 +1,3 @@ { - "autoload-dev": { - "psr-4": { - "Workbench\\App\\": "workbench/app", - "Workbench\\Database\\Factories\\": "workbench/database/factories", - "Workbench\\Database\\Seeders\\": "workbench/database/seeders" - } - } + "$schema": "https://getcomposer.org/schema.json" }