Skip to content

Commit d06f3a9

Browse files
authored
[10.x] Fix schedule:list to display named Jobs (#47367)
* Fix `schedule:list` to display named jobs * Extra test coverage * use in array * Rename * cs * cs
1 parent 3faf9ef commit d06f3a9

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ public function handle(Schedule $schedule)
8181
}
8282

8383
if ($event instanceof CallbackEvent) {
84-
if (class_exists($description)) {
85-
$command = $description;
86-
$description = '';
87-
} else {
84+
$command = $event->getSummaryForDisplay();
85+
86+
if (in_array($command, ['Closure', 'Callback'])) {
8887
$command = 'Closure at: '.$this->getClosureLocation($event);
8988
}
9089
}

tests/Integration/Console/Scheduling/ScheduleListCommandTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function testDisplaySchedule()
3636
$this->schedule->command('inspire')->twiceDaily(14, 18);
3737
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
3838
$this->schedule->job(FooJob::class)->everyMinute();
39+
$this->schedule->job(new FooParamJob('test'))->everyMinute();
40+
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
41+
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
3942
$this->schedule->command('inspire')->cron('0 9,17 * * *');
4043
$this->schedule->command('inspire')->cron("0 10\t* * *");
4144
$this->schedule->call(FooCall::class)->everyMinute();
@@ -51,9 +54,12 @@ public function testDisplaySchedule()
5154
->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now')
5255
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
5356
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now')
57+
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
58+
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
59+
->expectsOutput(' * * * * * foo-named-param-job ........ Next Due: 1 minute from now')
5460
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')
5561
->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now')
56-
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
62+
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
5763
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
5864
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now');
5965
}
@@ -64,6 +70,9 @@ public function testDisplayScheduleWithSort()
6470
$this->schedule->command('inspire')->twiceDaily(14, 18);
6571
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
6672
$this->schedule->job(FooJob::class)->everyMinute();
73+
$this->schedule->job(new FooParamJob('test'))->everyMinute();
74+
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
75+
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
6776
$this->schedule->command('inspire')->cron('0 9,17 * * *');
6877
$this->schedule->command('inspire')->cron("0 10\t* * *");
6978
$this->schedule->call(FooCall::class)->everyMinute();
@@ -77,7 +86,10 @@ public function testDisplayScheduleWithSort()
7786
->assertSuccessful()
7887
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
7988
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now')
80-
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
89+
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
90+
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
91+
->expectsOutput(' * * * * * foo-named-param-job ........ Next Due: 1 minute from now')
92+
->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now')
8193
->expectsOutput(' * * * * * Closure at: Illuminate\Tests\Integration\Console\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
8294
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now')
8395
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')
@@ -117,6 +129,13 @@ class FooJob
117129
{
118130
}
119131

132+
class FooParamJob
133+
{
134+
public function __construct($param)
135+
{
136+
}
137+
}
138+
120139
class FooCall
121140
{
122141
public function __invoke(): void

0 commit comments

Comments
 (0)