File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
Original file line number Diff line number Diff line change 8
8
use Illuminate \Contracts \Container \Container ;
9
9
use Illuminate \Contracts \Events \Dispatcher ;
10
10
use Illuminate \Support \ProcessUtils ;
11
+ use ReflectionClass ;
11
12
use Symfony \Component \Console \Application as SymfonyApplication ;
13
+ use Symfony \Component \Console \Attribute \AsCommand ;
12
14
use Symfony \Component \Console \Command \Command as SymfonyCommand ;
13
15
use Symfony \Component \Console \Exception \CommandNotFoundException ;
14
16
use Symfony \Component \Console \Input \ArrayInput ;
@@ -239,12 +241,18 @@ protected function addToParent(SymfonyCommand $command)
239
241
*/
240
242
public function resolve ($ command )
241
243
{
242
- if (is_subclass_of ($ command , SymfonyCommand::class) && ( $ commandName = $ command :: getDefaultName ()) ) {
243
- foreach ( explode ( ' | ' , $ commandName ) as $ name ) {
244
- $ this -> commandMap [ $ name ] = $ command ;
245
- }
244
+ if (is_subclass_of ($ command , SymfonyCommand::class)) {
245
+ $ attribute = ( new ReflectionClass ( $ command ))-> getAttributes (AsCommand::class);
246
+
247
+ $ commandName = ! empty ( $ attribute ) ? $ attribute [ 0 ]-> newInstance ()-> name : null ;
246
248
247
- return null ;
249
+ if (! is_null ($ commandName )) {
250
+ foreach (explode ('| ' , $ commandName ) as $ name ) {
251
+ $ this ->commandMap [$ name ] = $ command ;
252
+ }
253
+
254
+ return null ;
255
+ }
248
256
}
249
257
250
258
if ($ command instanceof Command) {
Original file line number Diff line number Diff line change 7
7
use Illuminate \Contracts \Console \Isolatable ;
8
8
use Illuminate \Foundation \Application ;
9
9
use Mockery as m ;
10
+ use Orchestra \Testbench \Concerns \InteractsWithMockery ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
use Symfony \Component \Console \Input \ArrayInput ;
12
13
use Symfony \Component \Console \Output \NullOutput ;
13
14
14
15
class CommandMutexTest extends TestCase
15
16
{
17
+ use InteractsWithMockery;
18
+
16
19
/**
17
20
* @var Command
18
21
*/
@@ -23,6 +26,8 @@ class CommandMutexTest extends TestCase
23
26
*/
24
27
protected $ commandMutex ;
25
28
29
+ /** {@inheritdoc} */
30
+ #[\Override]
26
31
protected function setUp (): void
27
32
{
28
33
$ this ->command = new class extends Command implements Isolatable
@@ -42,6 +47,13 @@ public function __invoke()
42
47
$ this ->command ->setLaravel ($ app );
43
48
}
44
49
50
+ /** {@inheritdoc} */
51
+ #[\Override]
52
+ protected function tearDown (): void
53
+ {
54
+ $ this ->tearDownTheTestEnvironmentUsingMockery ();
55
+ }
56
+
45
57
public function testCanRunIsolatedCommandIfNotBlocked ()
46
58
{
47
59
$ this ->commandMutex ->shouldReceive ('create ' )
You can’t perform that action at this time.
0 commit comments