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

Add CarbonSetTestNowToTravelToRector rule #240

Merged

Conversation

tamiroh
Copy link
Contributor

@tamiroh tamiroh commented Aug 11, 2024

Summary

This pull request proposes CarbonSetTestNowToTravelToRector which replace Carbon::setTestNow() with $this->travelTo(). This would make the following change.

use Illuminate\Foundation\Testing\TestCase;

class SomeTest extends TestCase
{
    public function test()
    {
-       Carbon::setTestNow('2024-08-11');
+       $this->travelTo('2024-08-11');
    }
}

Motivation

  • $this->travelTo() is simpler. 👍
  • When using Carbon in Laravel applications, we often confuse Carbon\Carbon and Illuminate\Support\Carbon. $this->travelTo() prevents it.
  • Carbon\Carbon::setTestNow() does not mock the result of Carbon\CarbonImmutable::now(). On the other hand, $this->travelTo() mocks both.

@tamiroh tamiroh changed the title Add CarbonSetTestNowToTravelToRector Add CarbonSetTestNowToTravelToRector rule Aug 11, 2024
@tamiroh tamiroh marked this pull request as ready for review August 11, 2024 13:30
@GeniJaho GeniJaho merged commit 8d39c5b into driftingly:main Aug 11, 2024
5 checks passed
@tamiroh tamiroh deleted the carbon-settestnow-to-travelto-rector branch August 11, 2024 23:25
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