From 10a9c18716ea5593669e634eef6599bddca46145 Mon Sep 17 00:00:00 2001 From: Oleg Voronkovich Date: Mon, 20 Feb 2023 20:09:11 +0300 Subject: [PATCH] Improve code --- src/DSNConfigurator.php | 12 ++++++-- test/PHPMailer/DSNConfiguratorTest.php | 41 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/DSNConfigurator.php b/src/DSNConfigurator.php index 5a0921ed..5def7223 100644 --- a/src/DSNConfigurator.php +++ b/src/DSNConfigurator.php @@ -78,8 +78,6 @@ class DSNConfigurator * @param array $config Configuration * * @throws Exception If scheme is invalid - * - * @return PHPMailer */ private function applyConfig(PHPMailer $mailer, $config) { @@ -145,6 +143,14 @@ class DSNConfigurator } } + /** + * Configure options. + * + * @param PHPMailer $mailer PHPMailer instance + * @param array $options Options + * + * @throws Exception If option is unknown + */ private function configureOptions(PHPMailer $mailer, $options) { $allowedOptions = get_object_vars($mailer); @@ -165,7 +171,7 @@ class DSNConfigurator sprintf( 'Unknown option: "%s". Allowed values: "%s"', $key, - implode('", "', $allowedOptions), + implode('", "', $allowedOptions) ) ); } diff --git a/test/PHPMailer/DSNConfiguratorTest.php b/test/PHPMailer/DSNConfiguratorTest.php index 0ebbe3b3..ba253357 100644 --- a/test/PHPMailer/DSNConfiguratorTest.php +++ b/test/PHPMailer/DSNConfiguratorTest.php @@ -19,8 +19,16 @@ use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\Test\TestCase; +/** + * Test configuring with DSN. + * + * @covers \PHPMailer\PHPMailer\DSNConfigurator + */ final class DSNConfiguratorTest extends TestCase { + /** + * Test throwing exception if DSN is invalid. + */ public function testInvalidDSN() { $configurator = new DSNConfigurator(); @@ -31,6 +39,9 @@ final class DSNConfiguratorTest extends TestCase $configurator->configure($this->Mail, 'localhost'); } + /** + * Test throwing exception if DSN scheme is invalid. + */ public function testInvalidScheme() { $configurator = new DSNConfigurator(); @@ -41,6 +52,9 @@ final class DSNConfiguratorTest extends TestCase $configurator->configure($this->Mail, 'ftp://localhost'); } + /** + * Test cofiguring mail. + */ public function testConfigureMail() { $configurator = new DSNConfigurator(); @@ -50,6 +64,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Mailer, 'mail'); } + /** + * Test cofiguring sendmail. + */ public function testConfigureSendmail() { $configurator = new DSNConfigurator(); @@ -59,6 +76,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Mailer, 'sendmail'); } + /** + * Test cofiguring qmail. + */ public function testConfigureQmail() { $configurator = new DSNConfigurator(); @@ -68,6 +88,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Mailer, 'qmail'); } + /** + * Test cofiguring SMTP without authentication. + */ public function testConfigureSmtpWithoutAuthentication() { $configurator = new DSNConfigurator(); @@ -79,6 +102,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertFalse($this->Mail->SMTPAuth); } + /** + * Test cofiguring SMTP with authentication. + */ public function testConfigureSmtpWithAuthentication() { $configurator = new DSNConfigurator(); @@ -93,6 +119,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Password, 'pass'); } + /** + * Test cofiguring SMTP without port. + */ public function testConfigureSmtpWithoutPort() { $configurator = new DSNConfigurator(); @@ -104,6 +133,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Port, SMTP::DEFAULT_PORT); } + /** + * Test cofiguring SMTP with port. + */ public function testConfigureSmtpWitPort() { $configurator = new DSNConfigurator(); @@ -115,6 +147,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Port, 2525); } + /** + * Test cofiguring SMTPs without port. + */ public function testConfigureSmtpsWithoutPort() { $configurator = new DSNConfigurator(); @@ -132,6 +167,9 @@ final class DSNConfiguratorTest extends TestCase $this->assertEquals($this->Mail->Password, 'pass'); } + /** + * Test cofiguring SMTPs with port. + */ public function testConfigureWithUnknownOption() { $configurator = new DSNConfigurator(); @@ -142,6 +180,9 @@ final class DSNConfiguratorTest extends TestCase $configurator->configure($this->Mail, 'mail://locahost?UnknownOption=Value'); } + /** + * Test cofiguring options with query sting. + */ public function testConfigureWithOptions() { $configurator = new DSNConfigurator();