-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add clock interface #7395
Add clock interface #7395
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## trunk #7395 +/- ##
============================================
+ Coverage 50.94% 50.96% +0.01%
- Complexity 11149 11159 +10
============================================
Files 613 614 +1
Lines 47062 47085 +23
Branches 404 405 +1
============================================
+ Hits 23975 23996 +21
- Misses 22760 22762 +2
Partials 327 327
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
Thank you @merkushin! Looks good and works well!
Maybe you're already planning it, but it's worth a reminder that it would be a good thing to document in P6rkRX-3bR-p2. :)
Looks good to me. Thanks! |
The added interface is similar to PSR-20. The difference is that we can pass the timezone to
now()
method as it is a common use-case in our codebase.The implementation is pretty straightforward and returns an immutable instance of current date and time.
There is a default test stub, which always returns the beginning of the Unix epoch (1970-01-01 00:00:00 in UTC). That's a shortcut to simplify testing.
However, if you need to run more complex tests you can replace the
clock
property inSensei_Main
with a custom mock or just use helper methods. See an example in the updated test.How it helps with time-based flaky tests? Those tests usually fail unexpectedly when time changed while test was running. To control time in our tests we add an abstraction over the system time function. Since this moment we can set expectations from time without being worry if time has changed.
Now, whenever you want to call
time()
, you should useSensei()->clock->now()
instead.Proposed Changes
Testing Instructions
Last Activity
column contains correct values.New/Updated Hooks
sensei_clock_init
— Filter clock object.Pre-Merge Checklist