Created
September 16, 2018 12:58
-
-
Save nikoheikkila/c7baf9a76bf67e58756fc6b5e0a88584 to your computer and use it in GitHub Desktop.
Quick Tip: Faking Dates in PHP with Carbon
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
// Set test date to 12:00 on 18th June, 2018 | |
$testDate = Carbon::create(2018, 6, 18, 12); | |
Carbon::setTestNow($testDate); | |
// Execute the logic | |
BusinessClass::doStuff(); | |
// Check the results | |
$this->assertDatabaseHas('stuff', [ | |
// The data you need... | |
]); | |
// IMPORTANT: Reset the date to not affect the next test! | |
Carbon::setTestNow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment