-
-
Notifications
You must be signed in to change notification settings - Fork 33
Register schedule commands #218
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
Merged
LukeTowers
merged 3 commits into
wintercms:develop
from
damsfx:Register-scheduler-commands
Jan 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| <?php | ||
|
|
||
| namespace Winter\Storm\Tests\Scheduling; | ||
|
|
||
| use Illuminate\Console\Command; | ||
| use Illuminate\Console\Scheduling\Schedule; | ||
| use Illuminate\Console\Scheduling\ScheduleListCommand; | ||
| use Illuminate\Support\Carbon; | ||
| use Illuminate\Support\ProcessUtils; | ||
|
|
||
| use Winter\Storm\Tests\TestCase; | ||
|
|
||
| class ScheduleListCommandTest extends TestCase | ||
| { | ||
| public $schedule; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| Carbon::setTestNow('2023-01-01'); | ||
| ScheduleListCommand::resolveTerminalWidthUsing(fn () => 80); | ||
|
|
||
| $this->schedule = $this->app->make(Schedule::class); | ||
| } | ||
|
|
||
| public function testDisplayEmptySchedule() | ||
| { | ||
| $this->artisan(ScheduleListCommand::class) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain('No scheduled tasks have been defined.'); | ||
| } | ||
|
|
||
| public function testDisplaySchedule() | ||
| { | ||
| $this->schedule->command(FooCommand::class)->quarterly(); | ||
| $this->schedule->command('inspire')->twiceDaily(14, 18); | ||
| $this->schedule->command('foobar', ['a' => 'b'])->everyMinute(); | ||
| $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; | ||
| $closureFilePath = __FILE__; | ||
|
|
||
| $this->artisan(ScheduleListCommand::class) | ||
| ->assertSuccessful() | ||
| ->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now') | ||
| ->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(' * * * * * Winter\Storm\Tests\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: Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now') | ||
| ->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall::fooFunction Next Due: 1 minute from now') | ||
| ->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now'); | ||
| } | ||
|
|
||
| public function testDisplayScheduleWithSort() | ||
| { | ||
| $this->schedule->command(FooCommand::class)->quarterly(); | ||
| $this->schedule->command('inspire')->twiceDaily(14, 18); | ||
| $this->schedule->command('foobar', ['a' => 'b'])->everyMinute(); | ||
| $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; | ||
| $closureFilePath = __FILE__; | ||
|
|
||
| $this->artisan(ScheduleListCommand::class, ['--next' => true]) | ||
| ->assertSuccessful() | ||
| ->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now') | ||
| ->expectsOutput(' * * * * * Winter\Storm\Tests\Scheduling\FooJob Next Due: 1 minute from now') | ||
| ->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now') | ||
| ->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\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') | ||
| ->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now') | ||
| ->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now'); | ||
| } | ||
|
|
||
| public function testDisplayScheduleInVerboseMode() | ||
| { | ||
| $this->schedule->command(FooCommand::class)->everyMinute(); | ||
|
|
||
| $this->artisan(ScheduleListCommand::class, ['-v' => true]) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain('Next Due: '.now()->setMinutes(1)->format('Y-m-d H:i:s P')) | ||
| ->expectsOutput(' ⇁ This is the description of the command.'); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| putenv('SHELL_VERBOSITY'); | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
| } | ||
|
|
||
| class FooCommand extends Command | ||
| { | ||
| protected $signature = 'foo:command'; | ||
|
|
||
| protected $description = 'This is the description of the command.'; | ||
| } | ||
|
|
||
| class FooJob | ||
| { | ||
| } | ||
|
|
||
| class FooParamJob | ||
| { | ||
| public function __construct($param) | ||
| { | ||
| } | ||
|
Comment on lines
+119
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suppress PHPMD unused-parameter warning for the stub. PHPMD flags 🔧 Suppress the unused-parameter warning class FooParamJob
{
+ /**
+ * `@SuppressWarnings`(PHPMD.UnusedFormalParameter)
+ */
public function __construct($param)
{
}
}🧰 Tools🪛 PHPMD (2.15.0)121-121: Avoid unused parameters such as '$param'. (undefined) (UnusedFormalParameter) 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| class FooCall | ||
| { | ||
| public function __invoke(): void | ||
| { | ||
| } | ||
|
|
||
| public function fooFunction(): void | ||
| { | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <?php | ||
|
|
||
| namespace Winter\Storm\Tests\Scheduling; | ||
|
|
||
| use Illuminate\Console\Application; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Console\Scheduling\Schedule; | ||
| use Illuminate\Console\Scheduling\ScheduleTestCommand; | ||
| use Illuminate\Support\Carbon; | ||
| use Winter\Storm\Tests\TestCase; | ||
|
|
||
| class ScheduleTestCommandTest extends TestCase | ||
| { | ||
| public $schedule; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| Carbon::setTestNow(now()->startOfYear()); | ||
|
|
||
| $this->schedule = $this->app->make(Schedule::class); | ||
| } | ||
|
|
||
| public function testRunNoDefinedCommands() | ||
| { | ||
| $this->artisan(ScheduleTestCommand::class) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain('No scheduled commands have been defined.'); | ||
| } | ||
|
|
||
| public function testRunNoMatchingCommand() | ||
| { | ||
| $this->schedule->command(BarCommandStub::class); | ||
|
|
||
| $this->artisan(ScheduleTestCommand::class, ['--name' => 'missing:command']) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain('No matching scheduled command found.'); | ||
| } | ||
|
|
||
| public function testRunUsingNameOption() | ||
| { | ||
| $this->schedule->command(BarCommandStub::class)->name('bar-command'); | ||
| $this->schedule->job(BarJobStub::class); | ||
| $this->schedule->call(fn () => true)->name('callback'); | ||
|
|
||
| $expectedOutput = windows_os() | ||
| ? 'Running ["artisan" bar:command]' | ||
| : "Running ['artisan' bar:command]"; | ||
|
|
||
| $this->artisan(ScheduleTestCommand::class, ['--name' => 'bar:command']) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain($expectedOutput); | ||
|
|
||
| $this->artisan(ScheduleTestCommand::class, ['--name' => BarJobStub::class]) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain(sprintf('Running [%s]', BarJobStub::class)); | ||
|
|
||
| $this->artisan(ScheduleTestCommand::class, ['--name' => 'callback']) | ||
| ->assertSuccessful() | ||
| ->expectsOutputToContain('Running [callback]'); | ||
| } | ||
|
|
||
| public function testRunUsingChoices() | ||
| { | ||
| $this->schedule->command(BarCommandStub::class)->name('bar-command'); | ||
| $this->schedule->job(BarJobStub::class); | ||
| $this->schedule->call(fn () => true)->name('callback'); | ||
|
|
||
| $this->artisan(ScheduleTestCommand::class) | ||
| ->assertSuccessful() | ||
| ->expectsChoice( | ||
| 'Which command would you like to run?', | ||
| 'callback', | ||
| [Application::formatCommandString('bar:command'), BarJobStub::class, 'callback'], | ||
| true | ||
| ) | ||
| ->expectsOutputToContain('Running [callback]'); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| parent::tearDown(); | ||
|
|
||
| Carbon::setTestNow(null); | ||
| } | ||
| } | ||
|
|
||
| class BarCommandStub extends Command | ||
| { | ||
| protected $signature = 'bar:command'; | ||
|
|
||
| protected $description = 'This is the description of the command.'; | ||
| } | ||
|
|
||
| class BarJobStub | ||
| { | ||
| public function __invoke() | ||
| { | ||
| // .. | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reset Carbon test time to avoid cross-test leakage.
setUp()freezes time; without clearing it, other tests can inherit the mocked clock.✅ Add cleanup in
tearDown()protected function tearDown(): void { + Carbon::setTestNow(null); putenv('SHELL_VERBOSITY'); parent::tearDown(); }🤖 Prompt for AI Agents