From 51f73458c8d1bc106b75f76d3c041719f11e31ac Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 17 Nov 2013 17:50:06 +0000 Subject: [PATCH] allow swiftmailer object to be passed in to Email Plugin. --- PHPCI/Plugin/Email.php | 13 +++++++++++-- Tests/PHPCI/Plugin/{Email.php => EmailTest.php} | 10 +++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) rename Tests/PHPCI/Plugin/{Email.php => EmailTest.php} (96%) diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index 7b80d795..83a41033 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -40,7 +40,11 @@ class Email implements \PHPCI\Plugin */ protected $mailer; - public function __construct(Builder $phpci, Build $build, array $options = array()) + public function __construct(Builder $phpci, + Build $build, + array $options = array(), + \Swift_Mailer $mailer = null + ) { $phpCiSettings = $phpci->getSystemConfig('phpci'); $this->phpci = $phpci; @@ -48,7 +52,12 @@ class Email implements \PHPCI\Plugin $this->options = $options; $this->emailConfig = isset($phpCiSettings['email_settings']) ? $phpCiSettings['email_settings'] : array(); - $this->loadSwiftMailerFromConfig(); + if ($mailer) { + $this->mailer = $mailer; + } + else { + $this->loadSwiftMailerFromConfig(); + } } /** diff --git a/Tests/PHPCI/Plugin/Email.php b/Tests/PHPCI/Plugin/EmailTest.php similarity index 96% rename from Tests/PHPCI/Plugin/Email.php rename to Tests/PHPCI/Plugin/EmailTest.php index 8000da7e..6fd5663e 100644 --- a/Tests/PHPCI/Plugin/Email.php +++ b/Tests/PHPCI/Plugin/EmailTest.php @@ -10,13 +10,12 @@ namespace PHPCI\Plugin\Tests; use PHPCI\Plugin\Email as EmailPlugin; -define('PHPCI_BIN_DIR', "FAKEPHPCIBIN"); /** * Unit test for the PHPUnit plugin. * @author meadsteve */ -class EmailTest extends \PHPUnit_Framework_TestCase +class EmailTest extends \PHPUnit_Framework_TestCase { /** @@ -43,7 +42,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase { $this->mockBuild = $this->getMock( '\PHPCI\Model\Build', - array('getLog'), + array('getLog', 'getStatus'), array(), "mockBuild", false @@ -53,6 +52,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase ->method('getLog') ->will($this->returnValue("Build Log")); + $this->mockBuild->expects($this->any()) + ->method('getStatus') + ->will($this->returnValue(\PHPCI\Model\Build::STATUS_SUCCESS)); + $this->mockCiBuilder = $this->getMock( '\PHPCI\Builder', array('getSystemConfig', @@ -96,6 +99,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase { $this->testedEmailPlugin = new EmailPlugin( $this->mockCiBuilder, + $this->mockBuild, $arrOptions, $this->mockMailer );