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

Time travel in tests #14253

Closed
dmoreno opened this issue Jul 8, 2016 · 3 comments
Closed

Time travel in tests #14253

dmoreno opened this issue Jul 8, 2016 · 3 comments

Comments

@dmoreno
Copy link
Contributor

dmoreno commented Jul 8, 2016

Carbon library has a very useful and easy to use feature to travel in time inside your tests:

$knownDate = Carbon::create(2001, 5, 21, 12); // create testing date
Carbon::setTestNow($knownDate);               // set the mock (of course this could be a real mock object)

This works with Laravel in most pieces of code, but not all. Because php built function time() is used 16 times in Laravel code base (I'm having issues with Cookie expire time generation).

As Carbon is a Laravel dependency, I thinks is possible to replace time() calls for Carbon equivalent. This way, time travel would be possible in Laravel tests. I think this would be awesome!

What do you think?

@dmoreno dmoreno changed the title Use of Carbon::setTestNow Time travel in tests Jul 8, 2016
@themsaid
Copy link
Member

themsaid commented Sep 6, 2016

Thank you for posting this, I wish I had known about it earlier in my career :D

@dmoreno
Copy link
Contributor Author

dmoreno commented Sep 26, 2016

@themsaid, thanks! good work!

@themsaid
Copy link
Member

@dmoreno :)

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

No branches or pull requests

2 participants