From de029d2fa4dc0362e236faf45f73a9fef2eefe27 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 14:48:07 +0800 Subject: [PATCH 1/4] :white_check_mark: wip Signed-off-by: Mior Muhammad Zaki --- tests/Console/stubs/composer.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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" } From c7828cad2d1b1a5386259c10597622bc622239ea Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 14:54:53 +0800 Subject: [PATCH 2/4] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 9cd57f7..87ac074 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -235,14 +235,22 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $content['autoload-dev']['psr-4'] = []; } + $namespacePrefix = ''; + + if (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( @@ -250,7 +258,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 assigned to [%s] namespace', $path, $autoloads[$path]), 'SKIPPED' ); } From dae89d7eeba70a7d334138afc3810deade1deebc Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 15:00:41 +0800 Subject: [PATCH 3/4] :white_check_mark: wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 4 ++-- tests/Console/DevToolCommandTest.php | 4 ++++ tests/Console/InstallCommandTest.php | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 87ac074..983ff4f 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -237,7 +237,7 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $namespacePrefix = ''; - if (confirm('Prefix with `Workbench` namespace?', default: true)) { + if ($this->components->confirm('Prefix with `Workbench` namespace?', default: true)) { $namespacePrefix = 'Workbench\\'; } @@ -258,7 +258,7 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files )); } else { $this->components->twoColumnDetail( - \sprintf('Composer already contain [%s] path assigned to [%s] namespace', $path, $autoloads[$path]), + \sprintf('Composer already contains [%s] path assigned to [%s] namespace', $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', From b666a6267160750f8bb10ce566e1af1771da4bab Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 11 Dec 2024 15:17:02 +0800 Subject: [PATCH 4/4] wip Signed-off-by: Mior Muhammad Zaki --- src/Console/DevToolCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/DevToolCommand.php b/src/Console/DevToolCommand.php index 983ff4f..ae0cf2d 100644 --- a/src/Console/DevToolCommand.php +++ b/src/Console/DevToolCommand.php @@ -254,11 +254,11 @@ protected function appendAutoloadDevToComposer(array $content, Filesystem $files $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 contains [%s] path assigned to [%s] namespace', $path, $autoloads[$path]), + \sprintf('Composer already contains [%s] path assigned to [%s] namespace', '/'.rtrim($path, '/'), $autoloads[$path]), 'SKIPPED' ); }