Repository navigation
jetpack: Catch calls to exit() and die() in PHPUnit - #21043
Conversation
It's too easy to wind up having WordPress just `exit()`, for example by having something call `wp_die()` while `wp_doing_ajax()` returns true. Let's use antecedent/patchwork (which we already use as part of brain/monkey in a bunch of package tests) to redefine these functions to throw an exception instead, which PHPUnit will catch.
|
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:
|
|
I like the approach. Although, I'm not sure how it actually works. There is an unrelated(?) failure in CI, and then there is a fatal |
|
So unfortunately it's not self-testing after all because GH merges with master and master already has the fix. The ExitException that was thrown there is a bug, which should be fixed by 3dc3d01. I didn't notice it locally because the Docker env uses a phar and a wrapper that loads all the PHPUnit classes before calling the bootstrap, while CI installs via |
Not that I blame them, PHP doesn't document the behavior or provide a way to do it properly.
|
Caution: This PR has changes that must be merged to WordPress.com |
|
The PHP 8 failure is a Patchwork bug, antecedent/patchwork#117. |
|
Finally there's a release of patchwork to fix the bug, so this can be ready to review again. |
|
Great news! One last step: head over to your WordPress.com diff, D66707-code, and commit it. Thank you! |
|
r233809-wpcom |
* master: (27 commits) Admin Page: Update upgrade buttons Tracks events (#21483) Debug Helper IDC Simulator: Add the ability to spoof the home url (#21516) Map block: Add `address` block attribute (#21412) Update wordpress monorepo (#21522) Stats Page: Add VideoPress nudge (#21513) Improve Jetpack products illustrations file size (#21514) Update dependency mediawiki/mediawiki-codesniffer to v38 (#21523) Update dependency yoast/phpunit-polyfills to v1.0.2 (#21524) Widgets: add Strava to Social Icons Widget and Social Menu (#21518) Boost: Add active modules to speed score request (#21471) Markdown: Better accessibility for Footnotes (#21495) Jetpack Plugin: Add VideoPress upgrade page (#21497) Admin Menu: moves Add new (plugin) menu item to the top for Atomic sites (#21506) General: Check the return value of get_comment() (#21080) Instagram Widget: link to user connection if user is not connected (#21512) Search: Create a new search package, rename Search plugin (#21502) Identity Crisis: Remove the unused jetpack_idc_option transient (#21492) Stats: do not update the wpcom blog details (#21441) Admin: do not display upgrade messages when on offline mode (#21444) jetpack: Catch calls to `exit()` and `die()` in PHPUnit (#21043) ...
Changes proposed in this Pull Request:
It's too easy to wind up having WordPress just
exit(), for example byhaving something call
wp_die()whilewp_doing_ajax()returns true.Let's use antecedent/patchwork (which we already use as part of
brain/monkey in a bunch of package tests) to redefine these functions to
throw an exception instead, which PHPUnit will catch.
Jetpack product discussion
p9dueE-3sh-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions:
exit()call somewhere in code covered by a test. Does PHPUnit still run to completion, with the relevant test showing that an unexpected ExitException was thrown?