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

Unit tests should run in a specified timezone #874

Open
1 task done
carstingaxion opened this issue Sep 17, 2024 · 3 comments
Open
1 task done

Unit tests should run in a specified timezone #874

carstingaxion opened this issue Sep 17, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@carstingaxion
Copy link
Collaborator

Describe the bug

Otherwise the created wp-env instance seems to take the OS settings, which will lead to some failing tests, if ran outside of GMT.

1) GatherPress\Tests\Core\Test_Event::test_get_display_datetime with data set #0 (array('2020-05-11 15:00:00', '2020-05-11 17:00:00'), 'Monday, May 11, 2020 3:00 PM ...T+0000')
Failed to assert display date times match.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Monday, May 11, 2020 3:00 PM to 5:00 PM GMT+0000'
+'Monday, May 11, 2020 3:00 PM to 5:00 PM CEST'

/var/www/html/wp-content/plugins/gatherpress/test/unit/php/includes/core/classes/class-test-event.php:119

2) GatherPress\Tests\Core\Test_Event::test_get_datetime
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
     'datetime_start_gmt' => ''
     'datetime_end' => ''
     'datetime_end_gmt' => ''
-    'timezone' => '+00:00'
+    'timezone' => 'Europe/Berlin'
 )

Steps to Reproduce

npm run test:unit:php

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@carstingaxion carstingaxion added the bug Something isn't working label Sep 17, 2024
@mauteri mauteri added the good first issue Good for newcomers label Sep 18, 2024
@carstingaxion
Copy link
Collaborator Author

This is so annoying, I keep getting different test results, when running locally and compared to when the workflow runs.

Just calling date_default_timezone_set() is heavily discouraged in combination with WordPress, but what to do alternatively?

@carstingaxion
Copy link
Collaborator Author

npm run wp-env destroy
npm run wp-env start

helped to solve this (for now). Not sure, if this should need to be prepared better. I'm fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants