VentureCraft / revisionable

Easily create a revision history for any laravel model
http://twitter.com/duellsy
MIT License
2.55k stars 348 forks source link

Ability to change created_at date for testing #384

Open sebas1208 opened 4 years ago

sebas1208 commented 4 years ago

First, I want to say thanks for the library, it has been really helpful in our project :clap:

I was wondering if there is a way to change the created_at for testing?

When you are testing sometimes is useful to create a revision at a certain point in time (e.g in the past). In my case, I have a query that relies on the created_at. And I want to create multiple revisions on different days in the past.

I tried to do Carbon::setTestNow(Carbon::create(2020, 10, 15)); (Carbon setTestNow) but this doesn't work, because the created_at (also updated_at) properties are created with new \DateTime().

Is it possible to change new \DateTime() with a Carbon::now() so we can use setTestNow for testing? (I can provide a PR) Or you know some way to accomplish what I want?

I know that I can create the revisions manually but then when you change the model, that creates more revisions and that affects the tests and also I believe with setTestNow the tests are more idiomatic.

Thanks for your help.