-
Notifications
You must be signed in to change notification settings - Fork 809
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
jetpack: Fix tests against WordPress master #21175
Conversation
Looks like WP went with Yoast\PHPUnitPolyfills\TestCases\TestCase.
No polyfill is provided.
They backported the polyfill stuff to 5.8, but not 5.8.1.
The string "jetpack_connection_active_plugins" is a key, not a value. It only accidentally worked before because `assertContains()` used to do `==` by default and `0.0 == "jetpack_connection_active_plugins"` is true.
…dividual_comments `assertContains` now does `===`, so we need to cast numeric-strings to ints.
…orts_data No idea why this fixes it, but it does.
No idea why this fixes this either.
It's annoying to have that cluttering the PHPUnit output.
* Paths are relative to the file, so no `tests/` prefix.
On hold waiting for a resolution on https://core.trac.wordpress.org/ticket/53911#comment:41. At the moment the master tests pass, but previous and latest don't due to that issue. |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
Caution: This PR has changes that must be merged to WordPress.com |
The `Yoast\PHPUnitPolyfills\TestCases\TestCase` base class already pulls them all in, and wpcom's tests don't seem to like them being explicitly included.
The way they set things up in WP 5.8 broke a few tests because the tests were somehow relying on the WP base set up or tear down not happening. Let's make that happen, then fix it.
This was broken in multiple ways: * It only hooked "added_option", not "updated_option" or "deleted_option". So it's not clear it was even testing what it claimed to be testing. * It would return whatever was in the cache for the option named "test_option", even though several of the tests were hooking for a different option name. * Some of the tests set "test_option" then checked that raw-setting some other option name didn't affect it. * It skipped the standard `WP_UnitTestCase_Base::tearDown()`, so the "test_option" option remained in the database, so "added_option" wasn't even being called to populate the cache. This fixes it by specifically hooking all four option-related events for the specific option name "test_option", and uses that in all the tests.
So take that into acocunt in `WP_Test_Jetpack_Deprecation::test_deprecated_file_paths`.
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.
Let's give it a go 👍
Great news! One last step: head over to your WordPress.com diff, D67335-code, and commit it. Thank you! |
r232368-wpcom |
…s WP 5.9 (#24086) * General: remove backwards compatibility code for user queries See #22559 * Update PHPUnit setup to remove WP < 5.9 oddities See #21175, #21157 Primary issue: #24082 * Update docs/examples/bootstrap.php Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> * Remove speed trap listener loder * Update doc to remove mention of temporary PHPUnit situation * Remove temporary line break workaround See #15595 * Remove custom function in favor of the one that ships with core * Remove old workaround for the Jetpack sidebar plugin icon See #14327 * Remove PHP 5.2 workaround See 99fffd8 * Add back necessary _wp_specialchars wrapping Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> Co-authored-by: Brandon Kraft <public@brandonkraft.com>
…Jetpack requires WP 5.9 (#24086) * General: remove backwards compatibility code for user queries See #22559 * Update PHPUnit setup to remove WP < 5.9 oddities See #21175, #21157 Primary issue: #24082 * Update docs/examples/bootstrap.php Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> * Remove speed trap listener loder * Update doc to remove mention of temporary PHPUnit situation * Remove temporary line break workaround See #15595 * Remove custom function in favor of the one that ships with core * Remove old workaround for the Jetpack sidebar plugin icon See #14327 * Remove PHP 5.2 workaround See 99fffd8 * Add back necessary _wp_specialchars wrapping Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com> Co-authored-by: Brandon Kraft <public@brandonkraft.com>
Changes proposed in this Pull Request:
Now that we have the infrastructure set up to run PHPUnit against WP's new
polyfilled setup, this fixes our tests against master to pass again.
Fix broken test suites
Switch setUp/tearDown for set_up/tear_down
Looks like WP went with Yoast\PHPUnitPolyfills\TestCases\TestCase.
Replace
assertInternalType()
with polyfilled alternativesReplace
assertContains
on strings withassertStringContainsString
Remove
assertArraySubset
. No polyfill is provided.Replace
assertRegExp
withassertMatchesRegularExpression
Replace
at()
, deprecated with no polyfillDon't use WordPress 5.8.1. They backported the polyfill stuff to 5.8, but
not 5.8.1.
Fix WP_Test_Jetpack_Site_Json_Api_Endpoints::test_get_site
The string "jetpack_connection_active_plugins" is a key, not a value. It
only accidentally worked before because
assertContains()
used to do==
by default and0.0 == "jetpack_connection_active_plugins"
istrue.
Fix WP_Test_Jetpack_Sync_Full_Immediately::test_full_sync_can_sync_individual_comments
assertContains
now does===
, so we need to cast numeric-strings toints.
Fix WP_Test_Jetpack_Sync_Themes::test_theme_callable_syncs_theme_supports_data
No idea why this fixes it, but it does.
Fix WP_Test_Jetpack_Sync_Updates::test_sync_wp_version
No idea why this fixes this either.
Don't write output in Test_CSS_Nudge_Customize_Control
It's annoying to have that cluttering the PHPUnit output.
Fix broken multisite test suites.
tests/
prefix.Require modules/subscriptions.php in subscriptions endpoint test
Add missing calls to parent::set_up() and so on
The way they set things up in WP 5.8 broke a few tests because the tests
were somehow relying on the WP base set up or tear down not happening.
Let's make that happen, then fix it.
Fix pseudo-cache in WP_Test_Jetpack_Options
This was broken in multiple ways:
"deleted_option". So it's not clear it was even testing what it
claimed to be testing.
"test_option", even though several of the tests were hooking for a
different option name.
other option name didn't affect it.
WP_UnitTestCase_Base::tearDown()
, sothe "test_option" option remained in the database, so "added_option"
wasn't even being called to populate the cache.
This fixes it by specifically hooking all four option-related events for
the specific option name "test_option", and uses that in all the tests.
Jetpack product discussion
p9dueE-3io-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions: