Skip to content

Commit a70b776

Browse files
[10.x] Fix command alias registration and usage (#50695)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Fix command alias parsing 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]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Update tests.yml * Update tests.yml * Update tests.yml * 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]> * 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]> Co-authored-by: Tim MacDonald <[email protected]>
1 parent a2d70b5 commit a70b776

File tree

7 files changed

+84
-29
lines changed

7 files changed

+84
-29
lines changed

.github/workflows/databases.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ jobs:
2929
steps:
3030
- name: Checkout code
3131
uses: actions/checkout@v4
32-
with:
33-
fetch-depth: 0
3432

3533
- name: Setup PHP
3634
uses: shivammathur/setup-php@v2
@@ -40,6 +38,9 @@ jobs:
4038
tools: composer:v2
4139
coverage: none
4240

41+
- name: Set Framework version
42+
run: composer config version "10.x-dev"
43+
4344
- name: Install dependencies
4445
uses: nick-fields/retry@v3
4546
with:
@@ -74,8 +75,6 @@ jobs:
7475
steps:
7576
- name: Checkout code
7677
uses: actions/checkout@v4
77-
with:
78-
fetch-depth: 0
7978

8079
- name: Setup PHP
8180
uses: shivammathur/setup-php@v2
@@ -85,6 +84,9 @@ jobs:
8584
tools: composer:v2
8685
coverage: none
8786

87+
- name: Set Framework version
88+
run: composer config version "10.x-dev"
89+
8890
- name: Install dependencies
8991
uses: nick-fields/retry@v3
9092
with:
@@ -119,8 +121,6 @@ jobs:
119121
steps:
120122
- name: Checkout code
121123
uses: actions/checkout@v4
122-
with:
123-
fetch-depth: 0
124124

125125
- name: Setup PHP
126126
uses: shivammathur/setup-php@v2
@@ -130,6 +130,9 @@ jobs:
130130
tools: composer:v2
131131
coverage: none
132132

133+
- name: Set Framework version
134+
run: composer config version "10.x-dev"
135+
133136
- name: Install dependencies
134137
uses: nick-fields/retry@v3
135138
with:
@@ -165,8 +168,6 @@ jobs:
165168
steps:
166169
- name: Checkout code
167170
uses: actions/checkout@v4
168-
with:
169-
fetch-depth: 0
170171

171172
- name: Setup PHP
172173
uses: shivammathur/setup-php@v2
@@ -176,6 +177,9 @@ jobs:
176177
tools: composer:v2
177178
coverage: none
178179

180+
- name: Set Framework version
181+
run: composer config version "10.x-dev"
182+
179183
- name: Install dependencies
180184
uses: nick-fields/retry@v3
181185
with:
@@ -209,8 +213,6 @@ jobs:
209213
steps:
210214
- name: Checkout code
211215
uses: actions/checkout@v4
212-
with:
213-
fetch-depth: 0
214216

215217
- name: Setup PHP
216218
uses: shivammathur/setup-php@v2
@@ -220,6 +222,9 @@ jobs:
220222
tools: composer:v2
221223
coverage: none
222224

225+
- name: Set Framework version
226+
run: composer config version "10.x-dev"
227+
223228
- name: Install dependencies
224229
uses: nick-fields/retry@v3
225230
with:

.github/workflows/facades.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
2422

2523
- name: Setup PHP
2624
uses: shivammathur/setup-php@v2

.github/workflows/queues.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
2422

2523
- name: Setup PHP
2624
uses: shivammathur/setup-php@v2
@@ -30,6 +28,9 @@ jobs:
3028
tools: composer:v2
3129
coverage: none
3230

31+
- name: Set Framework version
32+
run: composer config version "10.x-dev"
33+
3334
- name: Install dependencies
3435
uses: nick-fields/retry@v3
3536
with:
@@ -53,8 +54,6 @@ jobs:
5354
steps:
5455
- name: Checkout code
5556
uses: actions/checkout@v4
56-
with:
57-
fetch-depth: 0
5857

5958
- name: Setup PHP
6059
uses: shivammathur/setup-php@v2
@@ -64,6 +63,9 @@ jobs:
6463
tools: composer:v2
6564
coverage: none
6665

66+
- name: Set Framework version
67+
run: composer config version "10.x-dev"
68+
6769
- name: Install dependencies
6870
uses: nick-fields/retry@v3
6971
with:
@@ -95,8 +97,6 @@ jobs:
9597
steps:
9698
- name: Checkout code
9799
uses: actions/checkout@v4
98-
with:
99-
fetch-depth: 0
100100

101101
- name: Setup PHP
102102
uses: shivammathur/setup-php@v2
@@ -106,6 +106,9 @@ jobs:
106106
tools: composer:v2
107107
coverage: none
108108

109+
- name: Set Framework version
110+
run: composer config version "10.x-dev"
111+
109112
- name: Install dependencies
110113
uses: nick-fields/retry@v3
111114
with:
@@ -126,8 +129,6 @@ jobs:
126129
steps:
127130
- name: Checkout code
128131
uses: actions/checkout@v4
129-
with:
130-
fetch-depth: 0
131132

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

148+
- name: Set Framework version
149+
run: composer config version "10.x-dev"
150+
147151
- name: Install dependencies
148152
uses: nick-fields/retry@v3
149153
with:

.github/workflows/static-analysis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ jobs:
2121
steps:
2222
- name: Checkout code
2323
uses: actions/checkout@v4
24-
with:
25-
fetch-depth: 0
2624

2725
- name: Setup PHP
2826
uses: shivammathur/setup-php@v2
@@ -31,6 +29,9 @@ jobs:
3129
tools: composer:v2
3230
coverage: none
3331

32+
- name: Set Framework version
33+
run: composer config version "10.x-dev"
34+
3435
- name: Install dependencies
3536
uses: nick-fields/retry@v3
3637
with:

.github/workflows/tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ jobs:
4747
steps:
4848
- name: Checkout code
4949
uses: actions/checkout@v4
50-
with:
51-
fetch-depth: 0
5250

5351
- name: Setup PHP
5452
uses: shivammathur/setup-php@v2
@@ -62,6 +60,9 @@ jobs:
6260
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
6361
REDIS_LIBS: liblz4-dev, liblzf-dev, libzstd-dev
6462

63+
- name: Set Framework version
64+
run: composer config version "10.x-dev"
65+
6566
- name: Set minimum PHP 8.1 versions
6667
uses: nick-fields/retry@v3
6768
with:
@@ -121,8 +122,6 @@ jobs:
121122
122123
- name: Checkout code
123124
uses: actions/checkout@v4
124-
with:
125-
fetch-depth: 0
126125

127126
- name: Setup PHP
128127
uses: shivammathur/setup-php@v2
@@ -132,6 +131,9 @@ jobs:
132131
tools: composer:v2
133132
coverage: none
134133

134+
- name: Set Framework version
135+
run: composer config version "10.x-dev"
136+
135137
- name: Set Minimum PHP 8.1 Versions
136138
uses: nick-fields/retry@v3
137139
with:

src/Illuminate/Console/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ protected function addToParent(SymfonyCommand $command)
237237
public function resolve($command)
238238
{
239239
if (is_subclass_of($command, SymfonyCommand::class) && ($commandName = $command::getDefaultName())) {
240-
$this->commandMap[$commandName] = $command;
240+
foreach (explode('|', $commandName) as $name) {
241+
$this->commandMap[$name] = $command;
242+
}
241243

242244
return null;
243245
}

tests/Integration/Console/ConsoleApplicationTest.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
namespace Illuminate\Tests\Integration\Console;
44

5+
use Illuminate\Console\Application as Artisan;
56
use Illuminate\Console\Command;
67
use Illuminate\Console\Scheduling\Schedule;
78
use Illuminate\Contracts\Console\Kernel;
89
use Illuminate\Foundation\Console\QueuedCommand;
910
use Illuminate\Support\Facades\Queue;
1011
use Orchestra\Testbench\TestCase;
12+
use Symfony\Component\Console\Attribute\AsCommand;
1113

1214
class ConsoleApplicationTest extends TestCase
1315
{
1416
protected function setUp(): void
1517
{
16-
parent::setUp();
18+
Artisan::starting(function ($artisan) {
19+
$artisan->resolveCommands([
20+
FooCommandStub::class,
21+
ZondaCommandStub::class,
22+
]);
23+
});
1724

18-
$this->app[Kernel::class]->registerCommand(new FooCommandStub);
25+
parent::setUp();
1926
}
2027

2128
public function testArtisanCallUsingCommandName()
@@ -25,13 +32,34 @@ public function testArtisanCallUsingCommandName()
2532
])->assertExitCode(0);
2633
}
2734

35+
public function testArtisanCallUsingCommandNameAliases()
36+
{
37+
$this->artisan('app:foobar', [
38+
'id' => 1,
39+
])->assertExitCode(0);
40+
}
41+
2842
public function testArtisanCallUsingCommandClass()
2943
{
3044
$this->artisan(FooCommandStub::class, [
3145
'id' => 1,
3246
])->assertExitCode(0);
3347
}
3448

49+
public function testArtisanCallUsingCommandNameUsingAsCommandAttribute()
50+
{
51+
$this->artisan('zonda', [
52+
'id' => 1,
53+
])->assertExitCode(0);
54+
}
55+
56+
public function testArtisanCallUsingCommandNameAliasesUsingAsCommandAttribute()
57+
{
58+
$this->artisan('app:zonda', [
59+
'id' => 1,
60+
])->assertExitCode(0);
61+
}
62+
3563
public function testArtisanCallNow()
3664
{
3765
$exitCode = $this->artisan('foo:bar', [
@@ -86,6 +114,21 @@ class FooCommandStub extends Command
86114
{
87115
protected $signature = 'foo:bar {id}';
88116

117+
protected $aliases = ['app:foobar'];
118+
119+
public function handle()
120+
{
121+
//
122+
}
123+
}
124+
125+
#[AsCommand(name: 'zonda', aliases: ['app:zonda'])]
126+
class ZondaCommandStub extends Command
127+
{
128+
protected $signature = 'zonda {id}';
129+
130+
protected $aliases = ['app:zonda'];
131+
89132
public function handle()
90133
{
91134
//

0 commit comments

Comments
 (0)