Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Dec 11, 2024
2 parents 2b6ea81 + f8b7dac commit 435fa95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
22 changes: 15 additions & 7 deletions src/Console/DevToolCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
'<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 @@ -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',
Expand All @@ -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();
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/Console/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 1 addition & 7 deletions tests/Console/stubs/composer.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 435fa95

Please sign in to comment.