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

[6.x] Remove hardcoded Carbon reference from scheduler event #38063

Merged
merged 1 commit into from
Jul 19, 2021
Merged

[6.x] Remove hardcoded Carbon reference from scheduler event #38063

merged 1 commit into from
Jul 19, 2021

Conversation

axlon
Copy link
Contributor

@axlon axlon commented Jul 19, 2021

This pull request changes the date that is used to check if a scheduled event is due to the Date facade. I ran into a problem where my tests are failing because my application uses a different date class (CarbonImmutable)

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Date::use(CarbonImmutable::class);
    }
}

class MyTest extends TestCase
{
    public function testScheduler(): void
    {
        Date::setTestNow('...');

        $myEvent = '...';
        $dueEvents = $this->app->make(Schedule::class)->dueEvents($this->app);

        // This next line fails, because Carbon::now() returns the actual date
        $this->assertTrue($dueEvents->contains($myEvent));
    }
}

The following test will always fail because the scheduler calls Carbon directly, which at this point does not have a test instance set (because CarbonImmutable is used)

This shouldn't introduce any breaking changes because:

  • illuminate/console already requires illuminate/support
  • The \Illuminate\Console\Scheduling\Event class already uses the Date facade everywhere except the line that was changed

@axlon axlon changed the base branch from 8.x to 6.x July 19, 2021 12:19
@taylorotwell taylorotwell merged commit 176904e into laravel:6.x Jul 19, 2021
@axlon axlon deleted the fix-schedule-event-date-check branch July 19, 2021 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants