Improve tests

This commit is contained in:
Oleg Voronkovich 2023-02-20 18:38:42 +03:00
parent 52aebc52d5
commit 4ee7bfaf96
2 changed files with 49 additions and 5 deletions

View File

@ -123,7 +123,7 @@ class DSNConfigurator
$isSMTPS = 'smtps' === $config['scheme'];
if ($isSMTPS) {
$mailer->SMTPSecure = 'tls';
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
}
$mailer->Host = $config['host'];

View File

@ -15,6 +15,7 @@ namespace PHPMailer\Test\PHPMailer;
use PHPMailer\PHPMailer\DSNConfigurator;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\Test\TestCase;
@ -40,6 +41,15 @@ final class DSNConfiguratorTest extends TestCase
$configurator->configure($this->Mail, 'ftp://localhost');
}
public function testConfigureMail()
{
$configurator = new DSNConfigurator();
$configurator->configure($this->Mail, 'mail://localhost');
$this->assertEquals($this->Mail->Mailer, 'mail');
}
public function testConfigureSendmail()
{
$configurator = new DSNConfigurator();
@ -49,6 +59,15 @@ final class DSNConfiguratorTest extends TestCase
$this->assertEquals($this->Mail->Mailer, 'sendmail');
}
public function testConfigureQmail()
{
$configurator = new DSNConfigurator();
$configurator->configure($this->Mail, 'qmail://localhost');
$this->assertEquals($this->Mail->Mailer, 'qmail');
}
public function testConfigureSmtpWithoutAuthentication()
{
$configurator = new DSNConfigurator();
@ -67,12 +86,35 @@ final class DSNConfiguratorTest extends TestCase
$configurator->configure($this->Mail, 'smtp://user:pass@remotehost');
$this->assertEquals($this->Mail->Mailer, 'smtp');
$this->assertTrue($this->Mail->SMTPAuth);
$this->assertEquals($this->Mail->Host, 'remotehost');
$this->assertTrue($this->Mail->SMTPAuth);
$this->assertEquals($this->Mail->Username, 'user');
$this->assertEquals($this->Mail->Password, 'pass');
}
public function testConfigureSmtpWithoutPort()
{
$configurator = new DSNConfigurator();
$configurator->configure($this->Mail, 'smtp://localhost');
$this->assertEquals($this->Mail->Mailer, 'smtp');
$this->assertEquals($this->Mail->Host, 'localhost');
$this->assertEquals($this->Mail->Port, SMTP::DEFAULT_PORT);
}
public function testConfigureSmtpWitPort()
{
$configurator = new DSNConfigurator();
$configurator->configure($this->Mail, 'smtp://localhost:2525');
$this->assertEquals($this->Mail->Mailer, 'smtp');
$this->assertEquals($this->Mail->Host, 'localhost');
$this->assertEquals($this->Mail->Port, 2525);
}
public function testConfigureSmtpsWithoutPort()
{
$configurator = new DSNConfigurator();
@ -80,11 +122,13 @@ final class DSNConfiguratorTest extends TestCase
$configurator->configure($this->Mail, 'smtps://user:pass@remotehost');
$this->assertEquals($this->Mail->Mailer, 'smtp');
$this->assertEquals($this->Mail->SMTPSecure, 'tls');
$this->assertTrue($this->Mail->SMTPAuth);
$this->assertEquals($this->Mail->SMTPSecure, PHPMailer::ENCRYPTION_STARTTLS);
$this->assertEquals($this->Mail->Host, 'remotehost');
$this->assertEquals($this->Mail->Port, SMTP::DEFAULT_SECURE_PORT);
$this->assertTrue($this->Mail->SMTPAuth);
$this->assertEquals($this->Mail->Username, 'user');
$this->assertEquals($this->Mail->Password, 'pass');
$this->assertEquals($this->Mail->Port, SMTP::DEFAULT_SECURE_PORT);
}
}