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

Ability to change created_at date for testing #384

Open
sebas1208 opened this issue Oct 19, 2020 · 0 comments
Open

Ability to change created_at date for testing #384

sebas1208 opened this issue Oct 19, 2020 · 0 comments

Comments

@sebas1208
Copy link

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

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.

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

1 participant