You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can see a previous discussion at #41816 about a similar thing.
Just wondered if there was any interest in me PR'ing it to the framework itself?
if anyone's interested and just wants to grab it anyway
/** * Asserts that a command is registered with the console kernel schedular. * * @param string $command The artisan-format command (eg 'myapp:do-a-thing') or the class string name of the command (eg \App\Console\Commands\DoAThing::class) * @param string|null $schedule The schedule cron expression (eg '0 0 * * *') * @return void */protectedfunctionassertCommandIsScheduled(string$command, ?string$schedule = null)
{
$schedular = app(\Illuminate\Console\Scheduling\Schedule::class);
$originalCommand = $command;
if (class_exists($originalCommand)) {
$command = \Illuminate\Container\Container::getInstance()->make($originalCommand)->getName();
}
$matchingCommands = collect($schedular->events())->filter(
fn ($task) => str_ends_with($task->command, " 'artisan' {$command}")
);
if ($matchingCommands->isEmpty()) {
$this->fail("Command {$originalCommand} is not registered with the schedular");
}
if (! $schedule) {
$this->assertTrue(true);
return;
}
$this->assertNotEmpty($matchingCommands->filter(
fn ($task) => $task->expression === $schedule
), "Command {$originalCommand} is registered with the schedular but with " . ($matchingCommands->count() === 1 ? 'a different schedule' : 'different schedules') . "{$matchingCommands->pluck('expression')->implode(', ')}");
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a little custom test assertion I use in almost every project. It allows you to do things like :
I can see a previous discussion at #41816 about a similar thing.
Just wondered if there was any interest in me PR'ing it to the framework itself?
if anyone's interested and just wants to grab it anyway
Beta Was this translation helpful? Give feedback.
All reactions