From b158f9788806b1fbf0f64208742cba4e20f4f052 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 11:44:11 +0100 Subject: [PATCH 1/6] Fix `schedule:list` to display named jobs --- .../Console/Scheduling/ScheduleListCommand.php | 9 ++++----- .../Console/Scheduling/ScheduleListCommandTest.php | 9 +++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index e92b0112e696..14b5eaae2e24 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -81,11 +81,10 @@ public function handle(Schedule $schedule) } if ($event instanceof CallbackEvent) { - if (class_exists($description)) { - $command = $description; - $description = ''; - } else { - $command = 'Closure at: '.$this->getClosureLocation($event); + $command = $event->getSummaryForDisplay(); + + if ($command === 'Closure' || $command === 'Callback') { + $command = 'Closure at: ' . $this->getClosureLocation($event); } } diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index 4c0d6bcee70f..8bdd4cc61b15 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -6,6 +6,7 @@ use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\ScheduleListCommand; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\ProcessUtils; use Orchestra\Testbench\TestCase; @@ -36,6 +37,7 @@ 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(FooJob::class)->name('foo-named-job')->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); $this->schedule->call(FooCall::class)->everyMinute(); @@ -51,9 +53,10 @@ 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(' * * * * * foo-named-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'); } @@ -64,6 +67,7 @@ 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(FooJob::class)->name('foo-named-job')->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); $this->schedule->call(FooCall::class)->everyMinute(); @@ -77,7 +81,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(' * * * * * foo-named-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') From 7f42aa8e55da9c88d3a36ae518a866d0624860a9 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 12:20:38 +0100 Subject: [PATCH 2/6] Extra test coverage --- .../Console/Scheduling/ScheduleListCommandTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index 8bdd4cc61b15..f9564944bb94 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -37,7 +37,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 FooInstanceJob)->everyMinute(); $this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute(); + $this->schedule->job(new FooInstanceJob)->name('foo-named-instance-job')->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); $this->schedule->call(FooCall::class)->everyMinute(); @@ -53,7 +55,9 @@ 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\FooInstanceJob Next Due: 1 minute from now') ->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now') + ->expectsOutput(' * * * * * foo-named-instance-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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now') @@ -67,7 +71,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 FooInstanceJob)->everyMinute(); $this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute(); + $this->schedule->job(new FooInstanceJob)->name('foo-named-instance-job')->everyMinute(); $this->schedule->command('inspire')->cron('0 9,17 * * *'); $this->schedule->command('inspire')->cron("0 10\t* * *"); $this->schedule->call(FooCall::class)->everyMinute(); @@ -81,7 +87,9 @@ 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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooInstanceJob Next Due: 1 minute from now') ->expectsOutput(' * * * * * foo-named-job .............. Next Due: 1 minute from now') + ->expectsOutput(' * * * * * foo-named-instance-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') @@ -122,6 +130,10 @@ class FooJob { } +class FooInstanceJob +{ +} + class FooCall { public function __invoke(): void From e02d27e85abf9eba51092172b3514e3543594b54 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 12:34:21 +0100 Subject: [PATCH 3/6] use in array --- src/Illuminate/Console/Scheduling/ScheduleListCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index 14b5eaae2e24..bb9ed4bf761f 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -83,7 +83,7 @@ public function handle(Schedule $schedule) if ($event instanceof CallbackEvent) { $command = $event->getSummaryForDisplay(); - if ($command === 'Closure' || $command === 'Callback') { + if (in_array($command, ['Closure', 'Callback'])) { $command = 'Closure at: ' . $this->getClosureLocation($event); } } From dcabc6b907ff77924d986d19804f8612a29667b9 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 12:39:26 +0100 Subject: [PATCH 4/6] Rename --- .../Scheduling/ScheduleListCommandTest.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index f9564944bb94..f89f06b19a69 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -37,9 +37,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 FooInstanceJob)->everyMinute(); + $this->schedule->job(new FooParamJob('test'))->everyMinute(); $this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute(); - $this->schedule->job(new FooInstanceJob)->name('foo-named-instance-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(); @@ -55,9 +55,9 @@ 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\FooInstanceJob 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-instance-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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooCall Next Due: 1 minute from now') @@ -71,9 +71,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 FooInstanceJob)->everyMinute(); + $this->schedule->job(new FooParamJob('test'))->everyMinute(); $this->schedule->job(FooJob::class)->name('foo-named-job')->everyMinute(); - $this->schedule->job(new FooInstanceJob)->name('foo-named-instance-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(); @@ -87,9 +87,9 @@ 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(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooInstanceJob 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-instance-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') @@ -130,8 +130,11 @@ class FooJob { } -class FooInstanceJob +class FooParamJob { + public function __construct($param) { + + } } class FooCall From 5b3ffccdbb168543b66f0d4ca24e452e8a48a1ab Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 12:45:05 +0100 Subject: [PATCH 5/6] cs --- src/Illuminate/Console/Scheduling/ScheduleListCommand.php | 2 +- .../Console/Scheduling/ScheduleListCommandTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index bb9ed4bf761f..6a1128827183 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -84,7 +84,7 @@ public function handle(Schedule $schedule) $command = $event->getSummaryForDisplay(); if (in_array($command, ['Closure', 'Callback'])) { - $command = 'Closure at: ' . $this->getClosureLocation($event); + $command = 'Closure at: '.$this->getClosureLocation($event); } } diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index f89f06b19a69..45e9d607c325 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -6,7 +6,6 @@ use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\ScheduleListCommand; use Illuminate\Support\Carbon; -use Illuminate\Support\Facades\Artisan; use Illuminate\Support\ProcessUtils; use Orchestra\Testbench\TestCase; @@ -132,7 +131,8 @@ class FooJob class FooParamJob { - public function __construct($param) { + public function __construct($param) + { } } From 8575a381a7e63760bd0d893e5231f7870764d6d5 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 7 Jun 2023 12:45:45 +0100 Subject: [PATCH 6/6] cs --- tests/Integration/Console/Scheduling/ScheduleListCommandTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index 45e9d607c325..dae9de4a375a 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -133,7 +133,6 @@ class FooParamJob { public function __construct($param) { - } }