From 9c4970eaf9f753bd283994bb37ba39a534d58ee5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 13:24:35 +0800 Subject: [PATCH 1/6] [8.x] Prompts to configure generated namespace Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 12 +++++++++--- tests/Console/DevToolCommandTest.php | 11 +++++++++-- tests/Console/InstallCommandTest.php | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 91e1ee2..5755f91 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -237,10 +237,16 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $content['autoload-dev']['psr-4'] = []; } + $namespacePrefix = ''; + + if (confirm('Should prefix with `Workbench` namespace?', default: true, hint: 'Workbench\\')) { + $namespacePrefix = 'Workbench\\'; + } + $namespaces = [ - 'Workbench\\App\\' => 'workbench/app/', - 'Workbench\\Database\\Factories\\' => 'workbench/database/factories/', - 'Workbench\\Database\\Seeders\\' => 'workbench/database/seeders/', + $namespacePrefix.'App\\' => 'workbench/app/', + $namespacePrefix.'Database\\Factories\\' => 'workbench/database/factories/', + $namespacePrefix.'Database\\Seeders\\' => 'workbench/database/seeders/', ]; foreach ($namespaces as $namespace => $path) { diff --git a/tests/Console/DevToolCommandTest.php b/tests/Console/DevToolCommandTest.php index 74d6e95..90051f7 100644 --- a/tests/Console/DevToolCommandTest.php +++ b/tests/Console/DevToolCommandTest.php @@ -12,12 +12,14 @@ class DevToolCommandTest extends CommandTestCase public function it_can_run_devtool_command_with_installation(?string $answer, bool $createEnvironmentFile) { $this->artisan('workbench:devtool', ['--install' => true]) + ->expectsConfirmation('Should prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', '.env.example', '.env.dist', - ])->assertSuccessful(); + ]) + ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); $this->assertCommandExecutedWithInstall(); @@ -29,12 +31,14 @@ 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('Should prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', '.env.example', '.env.dist', - ])->assertSuccessful(); + ]) + ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); $this->assertCommandExecutedWithBasicInstall(); @@ -45,6 +49,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('Should prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); @@ -55,6 +60,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('Should prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); @@ -66,6 +72,7 @@ public function it_can_be_installed_with_prompt_for_missing_arguments() { $this->artisan('workbench:devtool') ->expectsConfirmation('Run Workbench installation?', false) + ->expectsConfirmation('Should prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); diff --git a/tests/Console/InstallCommandTest.php b/tests/Console/InstallCommandTest.php index 6c9ca9a..2390105 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('Should prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', From df309acc8583703b15e783f8845b7592eac6dd11 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 13:34:20 +0800 Subject: [PATCH 2/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 2 +- tests/Console/DevToolCommandTest.php | 10 +++++----- tests/Console/InstallCommandTest.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 5755f91..97c1170 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -239,7 +239,7 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $namespacePrefix = ''; - if (confirm('Should prefix with `Workbench` namespace?', default: true, hint: 'Workbench\\')) { + if (confirm('Prefix with `Workbench` namespace?', default: true)) { $namespacePrefix = 'Workbench\\'; } diff --git a/tests/Console/DevToolCommandTest.php b/tests/Console/DevToolCommandTest.php index 90051f7..bd86b05 100644 --- a/tests/Console/DevToolCommandTest.php +++ b/tests/Console/DevToolCommandTest.php @@ -12,7 +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('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', @@ -31,7 +31,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('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', @@ -49,7 +49,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('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); @@ -60,7 +60,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('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); @@ -72,7 +72,7 @@ public function it_can_be_installed_with_prompt_for_missing_arguments() { $this->artisan('workbench:devtool') ->expectsConfirmation('Run Workbench installation?', false) - ->expectsConfirmation('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); diff --git a/tests/Console/InstallCommandTest.php b/tests/Console/InstallCommandTest.php index 2390105..919f411 100644 --- a/tests/Console/InstallCommandTest.php +++ b/tests/Console/InstallCommandTest.php @@ -16,7 +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('Should prefix with `Workbench` namespace?', true) + ->expectsConfirmation('Prefix with `Workbench` namespace?', true) ->expectsChoice("Export '.env' file as?", $answer, [ 'Skip exporting .env', '.env', From 2514ecf82aaf42f657b68568ad84e55580ae1dc9 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 13:40:28 +0800 Subject: [PATCH 3/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 97c1170..69e0747 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -244,13 +244,15 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files } $namespaces = [ - $namespacePrefix.'App\\' => 'workbench/app/', - $namespacePrefix.'Database\\Factories\\' => 'workbench/database/factories/', - $namespacePrefix.'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( @@ -258,7 +260,7 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files )); } else { $this->components->twoColumnDetail( - \sprintf('Composer already contain [%s] namespace', $namespace), + \sprintf('Composer already contain [%s] path to use [%s] namespace', $path, $autoloads[$path]), 'SKIPPED' ); } From 5b9ee8a8d4a3df8a9bd1a4bab1b7b5693f991fde Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 14:50:58 +0800 Subject: [PATCH 4/6] wip Signed-off-by: Mior Muhammad Zaki --- tests/Console/DevToolCommandTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Console/DevToolCommandTest.php b/tests/Console/DevToolCommandTest.php index bd86b05..6be594e 100644 --- a/tests/Console/DevToolCommandTest.php +++ b/tests/Console/DevToolCommandTest.php @@ -18,8 +18,7 @@ public function it_can_run_devtool_command_with_installation(?string $answer, bo '.env', '.env.example', '.env.dist', - ]) - ->assertSuccessful(); + ])->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); $this->assertCommandExecutedWithInstall(); From d9cc12daaa1e0290493865711b11ef2e024c2acb Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 14:51:19 +0800 Subject: [PATCH 5/6] wip Signed-off-by: Mior Muhammad Zaki --- tests/Console/DevToolCommandTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Console/DevToolCommandTest.php b/tests/Console/DevToolCommandTest.php index 6be594e..7d850db 100644 --- a/tests/Console/DevToolCommandTest.php +++ b/tests/Console/DevToolCommandTest.php @@ -36,8 +36,7 @@ public function it_can_run_devtool_command_with_basic_installation(?string $answ '.env', '.env.example', '.env.dist', - ]) - ->assertSuccessful(); + ])->assertSuccessful(); $this->assertCommandExecutedWithDevTool(); $this->assertCommandExecutedWithBasicInstall(); From 5a44f51b222cb6f7022c7cbc3e47182626322b0f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 14:52:24 +0800 Subject: [PATCH 6/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 69e0747..9710a3e 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -260,7 +260,7 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files )); } else { $this->components->twoColumnDetail( - \sprintf('Composer already contain [%s] path to use [%s] namespace', $path, $autoloads[$path]), + \sprintf('Composer already contain [%s] path assigned to [%s] namespace', $path, $autoloads[$path]), 'SKIPPED' ); }