phplaraveldatetimephp-carbon

Laravel specify a date during testing


Is there any way to set an arbitrary date for Laravel's now() method to return? I have to test that my code works on different dates.


Solution

  • Carbon - Testing Aids: https://carbon.nesbot.com/docs/#api-testing

    Allows you to mock the time in tests with Carbon::setTestNow()

    And see Carbonite for more advanced features: https://github.com/kylekatarnls/carbonite