From d9045d54a712abada1de52042e3d44d2c2eed156 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 30 Jul 2014 11:58:10 +0100 Subject: [PATCH] Adding some tests for MailerFactory to ensure it works as expected with a provided configuration. Hopefully will help in debugging #523 --- PHPCI/Helper/MailerFactory.php | 2 +- Tests/PHPCI/Helper/MailerFactoryTest.php | 71 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Tests/PHPCI/Helper/MailerFactoryTest.php diff --git a/PHPCI/Helper/MailerFactory.php b/PHPCI/Helper/MailerFactory.php index 81d37831..b0ec4860 100644 --- a/PHPCI/Helper/MailerFactory.php +++ b/PHPCI/Helper/MailerFactory.php @@ -40,7 +40,7 @@ class MailerFactory return \Swift_Mailer::newInstance($transport); } - protected function getMailConfig($configName) + public function getMailConfig($configName) { if (isset($this->emailConfig[$configName]) && $this->emailConfig[$configName] != "") { return $this->emailConfig[$configName]; diff --git a/Tests/PHPCI/Helper/MailerFactoryTest.php b/Tests/PHPCI/Helper/MailerFactoryTest.php new file mode 100644 index 00000000..d4140c55 --- /dev/null +++ b/Tests/PHPCI/Helper/MailerFactoryTest.php @@ -0,0 +1,71 @@ + + */ +class MailerFactoryTest extends \PHPUnit_Framework_TestCase +{ + public function setUp() + { + } + + /** + * @covers PHPUnit::execute + */ + public function testExecute_TestGetMailConfig() + { + $config = array( + 'smtp_address' => 'mail.example.com', + 'smtp_port' => 225, + 'smtp_encryption' => true, + 'smtp_username' => 'example.user', + 'smtp_password' => 'examplepassword', + 'default_mailto_address' => 'phpci@example.com', + ); + + $factory = new MailerFactory(array('email_settings' => $config)); + + $this->assertEquals($config['smtp_address'], $factory->getMailConfig('smtp_address')); + $this->assertEquals($config['smtp_port'], $factory->getMailConfig('smtp_port')); + $this->assertEquals($config['smtp_encryption'], $factory->getMailConfig('smtp_encryption')); + $this->assertEquals($config['smtp_username'], $factory->getMailConfig('smtp_username')); + $this->assertEquals($config['smtp_password'], $factory->getMailConfig('smtp_password')); + $this->assertEquals($config['default_mailto_address'], $factory->getMailConfig('default_mailto_address')); + } + + /** + * @covers PHPUnit::execute + */ + public function testExecute_TestMailer() + { + $config = array( + 'smtp_address' => 'mail.example.com', + 'smtp_port' => 225, + 'smtp_encryption' => true, + 'smtp_username' => 'example.user', + 'smtp_password' => 'examplepassword', + 'default_mailto_address' => 'phpci@example.com', + ); + + $factory = new MailerFactory(array('email_settings' => $config)); + $mailer = $factory->getSwiftMailerFromConfig(); + + $this->assertEquals($config['smtp_address'], $mailer->getTransport()->getHost()); + $this->assertEquals($config['smtp_port'], $mailer->getTransport()->getPort()); + $this->assertEquals('tls', $mailer->getTransport()->getEncryption()); + $this->assertEquals($config['smtp_username'], $mailer->getTransport()->getUsername()); + $this->assertEquals($config['smtp_password'], $mailer->getTransport()->getPassword()); + } +}