From 4e63d08169874f498dab1b286d4adc8e8a12176e Mon Sep 17 00:00:00 2001 From: Bryce Lowe <bryce@brycelowe.com> Date: Sun, 12 May 2019 21:50:00 -0700 Subject: [PATCH] Added test cases for invalid transport method and invalid smtp configuration --- tests/lib/SimpleSAML/Utils/EMailTestCase.php | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/lib/SimpleSAML/Utils/EMailTestCase.php b/tests/lib/SimpleSAML/Utils/EMailTestCase.php index 971d6a278..ebd7b481e 100644 --- a/tests/lib/SimpleSAML/Utils/EMailTestCase.php +++ b/tests/lib/SimpleSAML/Utils/EMailTestCase.php @@ -5,6 +5,7 @@ namespace SimpleSAML\Test\Utils; use SimpleSAML\Test\Utils\TestCase; use SimpleSAML\Configuration; +use SimpleSAML\Utils\Config; use SimpleSAML\Utils\EMail; /** @@ -71,4 +72,34 @@ class EMailTestCase extends ClearStateTestCase { return [['mailtxt.twig'], ['mailhtml.twig']]; } + + public function testInvalidTransportConfiguration() + { + // preserve the original configuration + $originalTestConfiguration = Configuration::getInstance()->toArray(); + + // load the configuration with an invalid mail.transport.method + Configuration::loadFromArray(array_merge($originalTestConfiguration, [ + 'mail.transport.method' => 'foobar' + ]), '[ARRAY]', 'simplesaml'); + + + $this->expectException(\InvalidArgumentException::class); + new Email('Test', 'phpunit@simplesamlphp.org', 'phpunit@simplesamlphp.org'); + + // reset the configuration + Configuration::loadFromArray($originalTestConfiguration, '[ARRAY]', 'simplesaml'); + } + + public function testInvalidSMTPConfiguration() + { + // setup a new email + $email = new Email('Test', 'phpunit@simplesamlphp.org', 'phpunit@simplesamlphp.org'); + + // set the transport option to smtp but don't set any transport options (invalid state) + // NOTE: this is the same method that the constructor calls, so this should be logically equivalent + // to setting it via the configuration file. + $this->expectException(\InvalidArgumentException::class); + $email->setTransportMethod('smtp'); + } } -- GitLab