-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Clock] Provide modify()
in MockClock
#48189
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
Conversation
Hey! Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3". Cheers! Carsonbot |
dd49d4b
to
449c90d
Compare
I figured it's a bit late to get this into 6.2, which is why I targeted 6.3 even though the branch is not there yet. I know there were intense discussions about what should be part of the Clock in the original PR already, so feel free to close this if this functionality was omitted intentionally. |
449c90d
to
314d08b
Compare
Thanks for this proposal @dbrumann. In theory this addition looks reasonable ... but the Clock component has just been added. When things are so new, I think it's better to let people use it for some time. If something is annoying and requires a DX improvement, many people will complain about it and some will even report it here. |
I think it makes sense to add this to the |
I'm wondering if it wouldn't make more sense to expose a function that modifies the "now" while still using it as a reference. $this->clock->setTo($this->clock->now()->modify('3 weeks')); If the first example is confusion already, maybe the API is not the best :) What about a modify function instead? function modify(string $modifier): void
{
$this->now = $this->now->modifiy($modifier);
} |
I think both Lets say you want to test, that on Christmas Eve an email is send and not before, its more handy to use the WDYT? |
The var_dump((new DateTimeImmutable())->modify('2022-12-24'));
// 2022-12-24 10:49:34.003795 |
TIL; thanks |
With |
True. |
I used
|
To fuel the discussion, I'm using something similar to the new clock component for some time and I never have to alter the current date after initialization.
|
setTo()
in MockClock
setTo()
in MockClockmodify()
in MockClock
Can you please add a CHANGELOG entry? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor details and good to me thanks.
Can you please also update the PR description btw? |
8ebc7f8
to
ea442bd
Compare
ea442bd
to
4d3ce8f
Compare
Thank you @dbrumann. |
This is mostly for DX, especially when handling longer sleep periods and when having to change the time multiple times on a single MockClock-instance, e.g. when using a service from a booted kernel in functional tests.
This PR provides a way to modify the MockClock's current time by specifying either a relative string like "+2 days", which will forward the current clock-time by 2 days, or an absolute datetime like "2112-09-17 23:53:03". It uses
DateTimeImmutable::modify()
and supports the same modifiers.Example usage comparison between the already available sleep and modify: