-
Notifications
You must be signed in to change notification settings - Fork 293
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
Allow the system date to be mocked in PHPUnit tests. #6407
Comments
ACs here are good, moving to IB 👍🏻 |
@techanvil do we know if this is possible? We can of course introduce a mockable abstraction around |
@zutigrm The proposed solution doesn't seem to mock the main Is that possible to do? If not we should probably close this issue. At first I thought we could use namespaces (like under |
@tofumatt Thank you for the feedback. Yes correct, this will not mock the system time, the proposed change is targeting the 3 namespaces that use date/time functions, so this would mock the report time mainly (which seems to be the main need for why this issue was raised, unless I am getting that wrong). Mocking the system time, might be possible but we would need to bring in new testing library, that might help with that, just to achieve system time mock (although it might not guarantee the success). Not sure this would be recommended to do? |
It looks like we could redefine internal functions using runkit functions like Otherwise, I've used For things where WP's use of these functions is involved, I think changing our approach to the assertions should be all we need, as in #6758. |
Closing this for now as there isn't a way to mock the system time that would also affect WP without tinkering with core PHP functions which I think we should avoid (at least for now). If we do decide to use something like Aside from that, I think we can update our approach to some issues where we've seen fragility in our tests as mentioned above. |
Feature Description
We should provide the ability to mock the system date in PHPUnit tests, in order to be able to write more robust tests which use the date.
This is following up on this comment thread, and the related Analytics 4 test covering the default date range parameters should be rewritten with the mock date solution.
Additionally the codebase should be checked for any other PHPUnit tests which are using the system date and these should also be rewritten with mocked dates.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
gmdate
strtotime
Google\Site_Kit\Core\Util
Google\Site_Kit\Modules\Analytics_4\Report
Google\Site_Kit\Modules
time()
function based on the date set in the tests.Test Coverage
tests/phpunit/integration/Modules/Analytics_4Test.php
should be replaced with mocked method, no other test needs updatingQA Brief
Changelog entry
The text was updated successfully, but these errors were encountered: