Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila
Created September 16, 2018 12:58
Show Gist options
  • Save nikoheikkila/c7baf9a76bf67e58756fc6b5e0a88584 to your computer and use it in GitHub Desktop.
Save nikoheikkila/c7baf9a76bf67e58756fc6b5e0a88584 to your computer and use it in GitHub Desktop.
Quick Tip: Faking Dates in PHP with Carbon
// 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