diff --git a/test/PHPMailer/DKIMTest.php b/test/PHPMailer/DKIMTest.php index 6c89c2a6..1a6d65e2 100644 --- a/test/PHPMailer/DKIMTest.php +++ b/test/PHPMailer/DKIMTest.php @@ -25,6 +25,13 @@ use PHPMailer\Test\TestCase; final class DKIMTest extends TestCase { + /** + * Whether or not to initialize the PHPMailer object to throw exceptions. + * + * @var bool|null + */ + const USE_EXCEPTIONS = true; + const PRIVATE_KEY_FILE = 'dkim_private.pem'; /** @@ -250,7 +257,6 @@ final class DKIMTest extends TestCase $this->expectException(Exception::class); $this->expectExceptionMessage('Extension missing: openssl'); - $mail = new PHPMailer(true); - $mail->DKIM_Sign('foo'); + $this->Mail->DKIM_Sign('foo'); } } diff --git a/test/PHPMailer/MailTransportTest.php b/test/PHPMailer/MailTransportTest.php index 7b70753b..fbb6721b 100644 --- a/test/PHPMailer/MailTransportTest.php +++ b/test/PHPMailer/MailTransportTest.php @@ -81,7 +81,7 @@ final class MailTransportTest extends TestCase $this->setAddress('testmailsend@example.com', 'totest'); $this->setAddress('cctestmailsend@example.com', 'cctest', $sType = 'cc'); $this->setAddress('bcctestmailsend@example.com', 'bcctest', $sType = 'bcc'); - $this->Mail->addReplyTo('replytotestmailsend@example.com', 'replytotest'); + $this->setAddress('replytotestmailsend@example.com', 'replytotest', $sType = 'ReplyTo'); self::assertContains('testmailsend@example.com', $this->Mail->getToAddresses()[0], 'To address not found'); self::assertContains('cctestmailsend@example.com', $this->Mail->getCcAddresses()[0], 'CC address not found'); diff --git a/test/TestCase.php b/test/TestCase.php index c354bdfd..62786179 100644 --- a/test/TestCase.php +++ b/test/TestCase.php @@ -22,6 +22,17 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase as PolyfillTestCase; */ abstract class TestCase extends PolyfillTestCase { + + /** + * Whether or not to initialize the PHPMailer object to throw exceptions. + * + * Overload this constant in a concrete test class and set the value to `true` + * to initialize PHPMailer with Exceptions turned on. + * + * @var bool|null + */ + const USE_EXCEPTIONS = null; + /** * Holds the PHPMailer instance. * @@ -29,13 +40,6 @@ abstract class TestCase extends PolyfillTestCase */ protected $Mail; - /** - * Holds the SMTP mail host. - * - * @var string - */ - private $Host = ''; - /** * Holds the change log. * @@ -86,10 +90,17 @@ abstract class TestCase extends PolyfillTestCase } if (file_exists(\PHPMAILER_INCLUDE_DIR . '/test/testbootstrap.php')) { - include \PHPMAILER_INCLUDE_DIR . '/test/testbootstrap.php'; //Overrides go in here + include \PHPMAILER_INCLUDE_DIR . '/test/testbootstrap.php'; // Overrides go in here. } - $this->Mail = new PHPMailer(); - $this->Mail->SMTPDebug = SMTP::DEBUG_CONNECTION; //Full debug output + + // Initialize the PHPMailer class. + if (is_bool(static::USE_EXCEPTIONS)) { + $this->Mail = new PHPMailer(static::USE_EXCEPTIONS); + } else { + $this->Mail = new PHPMailer(); + } + + $this->Mail->SMTPDebug = SMTP::DEBUG_CONNECTION; // Full debug output. $this->Mail->Debugoutput = ['PHPMailer\Test\DebugLogTestListener', 'debugLog']; $this->Mail->Priority = 3; $this->Mail->Encoding = '8bit'; @@ -128,7 +139,7 @@ abstract class TestCase extends PolyfillTestCase if (array_key_exists('mail_userpass', $_REQUEST)) { $this->Mail->Password = $_REQUEST['mail_userpass']; } - $this->Mail->addReplyTo('no_reply@phpmailer.example.com', 'Reply Guy'); + $this->setAddress('no_reply@phpmailer.example.com', 'Reply Guy', 'ReplyTo'); $this->Mail->Sender = 'unit_test@phpmailer.example.com'; if ($this->Mail->Host != '') { $this->Mail->isSMTP(); @@ -148,7 +159,7 @@ abstract class TestCase extends PolyfillTestCase */ protected function tear_down() { - //Clean global variables + // Clean test class native properties between tests. $this->Mail = null; $this->ChangeLog = []; $this->NoteLog = []; @@ -161,7 +172,7 @@ abstract class TestCase extends PolyfillTestCase { $this->checkChanges(); - //Determine line endings for message + // Determine line endings for message. if ('text/html' === $this->Mail->ContentType || $this->Mail->AltBody !== '') { $eol = "
\r\n"; $bullet_start = '
  • '; @@ -189,7 +200,7 @@ abstract class TestCase extends PolyfillTestCase $ReportBody .= 'Host: ' . $this->Mail->Host . $eol; } - //If attachments then create an attachment list + // If attachments then create an attachment list. $attachments = $this->Mail->getAttachments(); if (count($attachments) > 0) { $ReportBody .= 'Attachments:' . $eol; @@ -202,7 +213,7 @@ abstract class TestCase extends PolyfillTestCase $ReportBody .= $list_end . $eol; } - //If there are changes then list them + // If there are changes then list them. if (count($this->ChangeLog) > 0) { $ReportBody .= 'Changes' . $eol; $ReportBody .= '-------' . $eol; @@ -215,7 +226,7 @@ abstract class TestCase extends PolyfillTestCase $ReportBody .= $list_end . $eol . $eol; } - //If there are notes then list them + // If there are notes then list them. if (count($this->NoteLog) > 0) { $ReportBody .= 'Notes' . $eol; $ReportBody .= '-----' . $eol; @@ -227,7 +238,7 @@ abstract class TestCase extends PolyfillTestCase $ReportBody .= $list_end; } - //Re-attach the original body + // Re-attach the original body. $this->Mail->Body .= $eol . $ReportBody; } @@ -304,6 +315,8 @@ abstract class TestCase extends PolyfillTestCase return $this->Mail->addCC($sAddress, $sName); case 'bcc': return $this->Mail->addBCC($sAddress, $sName); + case 'ReplyTo': + return $this->Mail->addReplyTo($sAddress, $sName); } return false;