Skip to content

Commit

Permalink
[10.x] Fix schedule:list to display named Jobs (#47367)
Browse files Browse the repository at this point in the history
* Fix `schedule:list` to display named jobs

* Extra test coverage

* use in array

* Rename

* cs

* cs
  • Loading branch information
liamkeily committed Jun 7, 2023
1 parent 3faf9ef commit d06f3a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Expand Up @@ -81,10 +81,9 @@ public function handle(Schedule $schedule)
}

if ($event instanceof CallbackEvent) {
if (class_exists($description)) {
$command = $description;
$description = '';
} else {
$command = $event->getSummaryForDisplay();

if (in_array($command, ['Closure', 'Callback'])) {
$command = 'Closure at: '.$this->getClosureLocation($event);
}
}
Expand Down
23 changes: 21 additions & 2 deletions tests/Integration/Console/Scheduling/ScheduleListCommandTest.php
Expand Up @@ -36,6 +36,9 @@ public function testDisplaySchedule()
$this->schedule->command('inspire')->twiceDaily(14, 18);
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
$this->schedule->job(FooJob::class)->everyMinute();
$this->schedule->job(new FooParamJob('test'))->everyMinute();
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
$this->schedule->command('inspire')->cron('0 9,17 * * *');
$this->schedule->command('inspire')->cron("0 10\t* * *");
$this->schedule->call(FooCall::class)->everyMinute();
Expand All @@ -51,9 +54,12 @@ public function testDisplaySchedule()
->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now')
->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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-param-job ........ 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(' * * * * * 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');
}
Expand All @@ -64,6 +70,9 @@ public function testDisplayScheduleWithSort()
$this->schedule->command('inspire')->twiceDaily(14, 18);
$this->schedule->command('foobar', ['a' => 'b'])->everyMinute();
$this->schedule->job(FooJob::class)->everyMinute();
$this->schedule->job(new FooParamJob('test'))->everyMinute();
$this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute();
$this->schedule->job(new FooParamJob('test'))->name('foo-named-param-job')->everyMinute();
$this->schedule->command('inspire')->cron('0 9,17 * * *');
$this->schedule->command('inspire')->cron("0 10\t* * *");
$this->schedule->call(FooCall::class)->everyMinute();
Expand All @@ -77,7 +86,10 @@ 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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooParamJob Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now')
->expectsOutput(' * * * * * foo-named-param-job ........ Next Due: 1 minute from now')
->expectsOutput(' * * * * * 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')
Expand Down Expand Up @@ -117,6 +129,13 @@ class FooJob
{
}

class FooParamJob
{
public function __construct($param)
{
}
}

class FooCall
{
public function __invoke(): void
Expand Down

0 comments on commit d06f3a9

Please sign in to comment.