Repository navigation
Build/Test Tools: Always reset the mock PHPMailer instance in tests - #13887
zakariabinsaifullah wants to merge 1 commit into
Conversation
`reset_phpmailer_instance()` only replaced the global `$phpmailer` when it was already set. If a test unset the global or set it to a falsey value, the helper returned early, and the next call to `wp_mail()` created a real `WP_PHPMailer` instance instead of the `MockPHPMailer`. The helper now always installs a fresh `MockPHPMailer`, so tests reliably send email through the mock. Includes tests covering an unset, `null`, `false`, or real mailer global. See #28618. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I'm still not sure if this is a better solution than #9403 Personally I'm inclined to close everything including #28618 unless @zakariabinsaifullah can give me more insight or an answer in the ticket to my last concerns. |
This implements the approach suggested by @SirLouen in comment:8: reset the mock mailer unconditionally.
reset_phpmailer_instance()only replaced the global$phpmailerwhen it was already truthy. If a test unset the global (or set it tonull/false), the helper returnedfalsewithout doing anything. The nextwp_mail()call then created a realWP_PHPMailer, so the test suite could send real email.Changes
tests/phpunit/includes/mock-mailer.php:reset_phpmailer_instance()now always installs a freshMockPHPMailerand returnstrue. No callers in the suite use the return value.tests/phpunit/tests/pluggable/wpMail.php: new tests (@ticket 28618) cover an unset global,null,falseand a realWP_PHPMailer, plus an end-to-end check thatwp_mail()goes through the mock after the global was unset.This is a test-suite-only change. It doesn't add the
wp_phpmailerfilter to core proposed in #10285. That PR now conflicts with trunk, and removing the override intests/phpunit/includes/install.phpwould leave the install step without a mock mailer. Whether core should get a filter can be decided on the ticket separately.Testing (local, MariaDB 13, PHP 8.5)
wp_mail()ends up using a realWP_PHPMailerafter the global is unset.wpMail.php: OK (37 tests, 95 assertions)--group mail: OK (39 tests)reset_phpmailer_instance()passes:comment.php,user.php,user/wpSendUserRequest.php, and the threeprivacy/wpPrivacySend*files.phpcspasses on both changed files.Trac ticket: https://core.trac.wordpress.org/ticket/28618
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Analyzing the ticket history, drafting the fix and tests, and running the test suite. I reviewed the final changes and take responsibility for them.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.