Use the $this->travelTo()
method in Laravel's TestCase
class instead of the Carbon::setTestNow()
method.
use Illuminate\Support\Carbon;
use Illuminate\Foundation\Testing\TestCase;
class SomeTest extends TestCase
{
public function test()
{
- Carbon::setTestNow('2024-08-11');
+ $this->travelTo('2024-08-11');
}
}
Configure your rector.php
:
<?php
use RectorLaravel\Rector\StaticCall\CarbonSetTestNowToTravelToRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
CarbonSetTestNowToTravelToRector::class,
]);