Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix schedule:list crash when call() is given class-string #45306

Merged
merged 2 commits into from Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Expand Up @@ -220,7 +220,15 @@ private function getClosureLocation(CallbackEvent $event)
);
}

if (is_string($callback)) {
return $callback;
}

if (is_array($callback)) {
if (is_string($callback[0])) {
odinns marked this conversation as resolved.
Show resolved Hide resolved
return sprintf('%s::%s', $callback[0], $callback[1]);
}

return sprintf('%s::%s', $callback[0]::class, $callback[1]);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Integration/Console/Scheduling/ScheduleListCommandTest.php
Expand Up @@ -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;
Expand All @@ -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');
}

Expand All @@ -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;
Expand All @@ -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')
Expand Down Expand Up @@ -106,3 +114,14 @@ class FooCommand extends Command
class FooJob
{
}

class FooCall
{
public function __invoke(): void
{
}

public function fooFunction(): void
{
}
}