Skip to content

Commit

Permalink
Merge pull request #61 from orchestral/7/confirm-namespace-prefix
Browse files Browse the repository at this point in the history
* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* ✅ wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Dec 11, 2024
2 parents de029d2 + b666a62 commit f8b7dac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/Console/DevToolCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
'<fg=yellow;options=bold>SKIPPED</>'
);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Console/DevToolCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/Console/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f8b7dac

Please sign in to comment.