[wp-trac] [WordPress Trac] #28618: Allow PHPMailer class to be reliably overriden
WordPress Trac
noreply at wordpress.org
Wed Aug 20 11:39:55 UTC 2025
#28618: Allow PHPMailer class to be reliably overriden
-------------------------------------------------+-------------------------
Reporter: leewillis77 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Mail | Version: 4.0
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests good- | Focuses:
first-bug has-test-info |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: has-patch has-unit-tests close reporter-feedback => needs-
patch needs-unit-tests good-first-bug has-test-info
* type: enhancement => defect (bug)
Comment:
Ok, after doing a little more research, yes I could reproduce this in a
single test, but I could not reproduce in a plugin as the reporter
suggested, because tests run in a different DB, and there should not be
any `active_plugins` in the `wp_options` table by default unless we are
doing something very wrong. This plugin thing was misdirecting my
attention.
But now I've been looking into how the `tear_down` in `wpMail` is running
the `reset_phpmailer_instance`.
The reality is that, if we test this way:
{{{
/**
* @group sample
*/
public function test_unsetting_phpmailer_instance() {
global $phpmailer;
$phpmailer = null;
$this->assertNull( $phpmailer );
}
/**
* @group sample
*/
public function test_random_delivery() {
wp_mail( 'test at example.com', 'Test', 'Test' );
global $phpmailer;
$this->assertInstanceOf( 'MockPHPMailer', $phpmailer );
}
}}}
The PHPMailer instance is not being completely reset in `tear_down` in
`reset_phpmailer_instance` and the email is being sent with a regular
PHPMailer object.
This section of code is not doing the job:
https://github.com/WordPress/wordpress-
develop/blob/3ea6be9fa8a4973c2b01c094f062de4fd33c0aba/tests/phpunit/includes
/mock-mailer.php#L110-L123
The problem is that the `$mailer` conditional is not covering the scenario
where `$phpmailer` is unset.
This was addressed in [41185], but was not sufficiently addressed, not
covering this edge case. What I'm trying to devise is why the conditional
was introduced first in [37358].
I think that the object should be reset unconditionally. I would like to
see a patch proposal.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28618#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list