Created
May 13, 2021 08:19
-
-
Save micc83/555c37ed4af8ae7afc21692e2b80bb70 to your computer and use it in GitHub Desktop.
Assert a given command is scheduled once on Laravel Task Scheduling
This file contains 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
<?php | |
namespace Tests; | |
use Illuminate\Console\Scheduling\Event; | |
use Illuminate\Console\Scheduling\Schedule; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
use Illuminate\Support\Str; | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
protected function assertScheduledOnce(string $command, string $cronExpression): void | |
{ | |
$scheduler = $this->app->make(Schedule::class); | |
$events = collect($scheduler->events())->filter( | |
fn (Event $event) => Str::contains($event->command, $command) | |
); | |
$this->assertCount(1, $events); | |
/** @var Event $event */ | |
$event = $events->first(); | |
$this->assertEquals($cronExpression, $event->expression); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment