Add shortcut PHPMailer::fromDSN()

This commit is contained in:
Oleg Voronkovich 2023-02-20 20:32:16 +03:00
parent 10a9c18716
commit ecc11e3bf5
2 changed files with 38 additions and 0 deletions

View File

@ -5123,4 +5123,19 @@ class PHPMailer
{
$this->oauth = $oauth;
}
/**
* Create new instance configured by DSN.
*
* @param string $dsn DSN
* @param bool $exceptions Should we throw external exceptions?
*
* @return PHPMailer
*/
public static function fromDSN($dsn, $exceptions = null)
{
static $configurator = new DSNConfigurator();
return $configurator->configure(new PHPMailer($exceptions), $dsn);
}
}

View File

@ -194,4 +194,27 @@ final class DSNConfiguratorTest extends TestCase
$this->assertEquals($this->Mail->AllowEmpty, true);
$this->assertEquals($this->Mail->WordWrap, 78);
}
/**
* Test shortcut.
*
* @covers \PHPMailer\PHPMailer\PHPMailer::fromDSN
*/
public function testShorcut()
{
$mailer = PHPMailer::fromDSN('smtps://user@gmail.com:secret@smtp.gmail.com?SMTPDebug=3&Timeout=1000');
$this->assertEquals($mailer->Mailer, 'smtp');
$this->assertEquals($mailer->SMTPSecure, PHPMailer::ENCRYPTION_STARTTLS);
$this->assertEquals($mailer->Host, 'smtp.gmail.com');
$this->assertEquals($mailer->Port, SMTP::DEFAULT_SECURE_PORT);
$this->assertTrue($mailer->SMTPAuth);
$this->assertEquals($mailer->Username, 'user@gmail.com');
$this->assertEquals($mailer->Password, 'secret');
$this->assertEquals($mailer->SMTPDebug, 3);
$this->assertEquals($mailer->Timeout, 1000);
}
}