Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix command alias registration and usage #50695

Merged
merged 13 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions .github/workflows/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -40,6 +38,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -74,8 +75,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -85,6 +84,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -119,8 +121,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -130,6 +130,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -165,8 +168,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -176,6 +177,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -209,8 +213,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -220,6 +222,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/facades.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/queues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -30,6 +28,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand All @@ -53,8 +54,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -64,6 +63,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -95,8 +97,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -106,6 +106,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand All @@ -126,8 +129,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download & Extract beanstalkd
run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
Expand All @@ -144,6 +145,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -31,6 +29,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Install dependencies
uses: nick-fields/retry@v3
with:
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -62,6 +60,9 @@ jobs:
REDIS_CONFIGURE_OPTS: --enable-redis --enable-redis-igbinary --enable-redis-msgpack --enable-redis-lzf --with-liblzf --enable-redis-zstd --with-libzstd --enable-redis-lz4 --with-liblz4
REDIS_LIBS: liblz4-dev, liblzf-dev, libzstd-dev

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Set minimum PHP 8.1 versions
uses: nick-fields/retry@v3
with:
Expand Down Expand Up @@ -121,8 +122,6 @@ jobs:

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -132,6 +131,9 @@ jobs:
tools: composer:v2
coverage: none

- name: Set Framework version
run: composer config version "10.x-dev"

- name: Set Minimum PHP 8.1 Versions
uses: nick-fields/retry@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ protected function addToParent(SymfonyCommand $command)
public function resolve($command)
{
if (is_subclass_of($command, SymfonyCommand::class) && ($commandName = $command::getDefaultName())) {
$this->commandMap[$commandName] = $command;
foreach (explode('|', $commandName) as $name) {
$this->commandMap[$name] = $command;
}

return null;
}
Expand Down
47 changes: 45 additions & 2 deletions tests/Integration/Console/ConsoleApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

namespace Illuminate\Tests\Integration\Console;

use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Console\QueuedCommand;
use Illuminate\Support\Facades\Queue;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Console\Attribute\AsCommand;

class ConsoleApplicationTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Artisan::starting(function ($artisan) {
$artisan->resolveCommands([
FooCommandStub::class,
ZondaCommandStub::class,
]);
});

$this->app[Kernel::class]->registerCommand(new FooCommandStub);
parent::setUp();
}

public function testArtisanCallUsingCommandName()
Expand All @@ -25,13 +32,34 @@ public function testArtisanCallUsingCommandName()
])->assertExitCode(0);
}

public function testArtisanCallUsingCommandNameAliases()
{
$this->artisan('app:foobar', [
'id' => 1,
])->assertExitCode(0);
}

public function testArtisanCallUsingCommandClass()
{
$this->artisan(FooCommandStub::class, [
'id' => 1,
])->assertExitCode(0);
}

public function testArtisanCallUsingCommandNameUsingAsCommandAttribute()
{
$this->artisan('zonda', [
'id' => 1,
])->assertExitCode(0);
}

public function testArtisanCallUsingCommandNameAliasesUsingAsCommandAttribute()
{
$this->artisan('app:zonda', [
'id' => 1,
])->assertExitCode(0);
}

public function testArtisanCallNow()
{
$exitCode = $this->artisan('foo:bar', [
Expand Down Expand Up @@ -86,6 +114,21 @@ class FooCommandStub extends Command
{
protected $signature = 'foo:bar {id}';

protected $aliases = ['app:foobar'];

public function handle()
{
//
}
}

#[AsCommand(name: 'zonda', aliases: ['app:zonda'])]
class ZondaCommandStub extends Command
{
protected $signature = 'zonda {id}';

protected $aliases = ['app:zonda'];

public function handle()
{
//
Expand Down