diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index 03a2b23f6e30..155095874cd1 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -220,8 +220,14 @@ private function getClosureLocation(CallbackEvent $event) ); } + if (is_string($callback)) { + return $callback; + } + if (is_array($callback)) { - return sprintf('%s::%s', $callback[0]::class, $callback[1]); + $className = is_string($callback[0]) ? $callback[0] : $callback[0]::class; + + return sprintf('%s::%s', $className, $callback[1]); } return sprintf('%s::__invoke', $callback::class); diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index efa6f60d8b20..2b32a7d5585e 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -36,6 +36,8 @@ public function testDisplaySchedule() $this->schedule->job(FooJob::class)->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); + $this->schedule->call(FooCall::class)->everyMinute(); + $this->schedule->call([FooCall::class, 'fooFunction'])->everyMinute(); $this->schedule->call(fn () => '')->everyMinute(); $closureLineNumber = __LINE__ - 1; @@ -49,6 +51,8 @@ public function testDisplaySchedule() ->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now') ->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now') ->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now') + ->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now') + ->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now') ->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now'); } @@ -60,6 +64,8 @@ public function testDisplayScheduleWithSort() $this->schedule->job(FooJob::class)->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); + $this->schedule->call(FooCall::class)->everyMinute(); + $this->schedule->call([FooCall::class, 'fooFunction'])->everyMinute(); $this->schedule->call(fn () => '')->everyMinute(); $closureLineNumber = __LINE__ - 1; @@ -69,6 +75,8 @@ public function testDisplayScheduleWithSort() ->assertSuccessful() ->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now') ->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now') + ->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now') + ->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now') ->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now') ->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now') ->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now') @@ -106,3 +114,14 @@ class FooCommand extends Command class FooJob { } + +class FooCall +{ + public function __invoke(): void + { + } + + public function fooFunction(): void + { + } +}