Added basic body and title for the email notifications.
This commit is contained in:
parent
33b840a82d
commit
84370038aa
|
@ -135,6 +135,13 @@ class Builder
|
|||
return $this->build;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The title of the project being built.
|
||||
*/
|
||||
public function getBuildProjectTitle() {
|
||||
return $this->getBuild()->getProject()->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the build has passed or failed.
|
||||
* @return bool
|
||||
|
|
|
@ -73,20 +73,22 @@ class Email implements \PHPCI\Plugin
|
|||
|
||||
$sendFailures = array();
|
||||
|
||||
$subjectTemplate = "PHPCI - %s - %s";
|
||||
$projectName = $this->phpci->getBuildProjectTitle();
|
||||
$logText = $this->phpci->getBuild()->getLog();
|
||||
|
||||
if($this->phpci->getSuccessStatus()) {
|
||||
$body = "";
|
||||
$sendFailures = $this->sendSeparateEmails(
|
||||
$addresses,
|
||||
"PASSED",
|
||||
$body
|
||||
sprintf($subjectTemplate, $projectName, "Passing Build"),
|
||||
sprintf("Log Output: <br><pre>%s</pre>", $logText)
|
||||
);
|
||||
}
|
||||
else {
|
||||
$body = "";
|
||||
$sendFailures = $this->sendSeparateEmails(
|
||||
$addresses,
|
||||
"FAILED",
|
||||
$body
|
||||
sprintf($subjectTemplate, $projectName, "Failing Build"),
|
||||
sprintf("Log Output: <br><pre>%s</pre>", $logText)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -113,7 +115,8 @@ class Email implements \PHPCI\Plugin
|
|||
$message = \Swift_Message::newInstance($subject)
|
||||
->setFrom($this->getMailConfig('from_address'))
|
||||
->setTo($toAddresses)
|
||||
->setBody($body);
|
||||
->setBody($body)
|
||||
->setContentType("text/html");
|
||||
$failedAddresses = array();
|
||||
$this->mailer->send($message, $failedAddresses);
|
||||
|
||||
|
|
|
@ -34,16 +34,38 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
protected $mockMailer;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject $mockMailer
|
||||
*/
|
||||
protected $mockBuild;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockBuild = $this->getMock(
|
||||
'\PHPCI\Model\Build',
|
||||
array('getLog'),
|
||||
array(),
|
||||
"mockBuild",
|
||||
false
|
||||
);
|
||||
|
||||
$this->mockBuild->expects($this->any())
|
||||
->method('getLog')
|
||||
->will($this->returnValue("Build Log"));
|
||||
|
||||
$this->mockCiBuilder = $this->getMock(
|
||||
'\PHPCI\Builder',
|
||||
array('getSystemConfig'),
|
||||
array('getSystemConfig',
|
||||
'getBuildProjectTitle',
|
||||
'getBuild',
|
||||
'log'),
|
||||
array(),
|
||||
"mockBuilder",
|
||||
false
|
||||
);
|
||||
$this->mockCiBuilder->buildPath = "/";
|
||||
|
||||
$this->mockCiBuilder->buildPath = "/";
|
||||
|
||||
$this->mockCiBuilder->expects($this->any())
|
||||
->method('getSystemConfig')
|
||||
->with('phpci')
|
||||
|
@ -52,6 +74,12 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
'from_address' => "test-from-address@example.com"
|
||||
)
|
||||
)));
|
||||
$this->mockCiBuilder->expects($this->any())
|
||||
->method('getBuildProjectTitle')
|
||||
->will($this->returnValue('Test-Project'));
|
||||
$this->mockCiBuilder->expects($this->any())
|
||||
->method('getBuild')
|
||||
->will($this->returnValue($this->mockBuild));
|
||||
|
||||
$this->mockMailer = $this->getMock(
|
||||
'\Swift_Mailer',
|
||||
|
@ -85,6 +113,35 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($expectedReturn, $returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_BuildsBasicEmails()
|
||||
{
|
||||
$this->loadEmailPluginWithOptions(array(
|
||||
'addresses' => array('test-receiver@example.com')
|
||||
));
|
||||
|
||||
/** @var \Swift_Message $actualMail */
|
||||
$actualMail = null;
|
||||
$this->catchMailPassedToSend($actualMail);
|
||||
|
||||
$returnValue = $this->testedEmailPlugin->execute();
|
||||
$expectedReturn = true;
|
||||
|
||||
$this->assertSystemMail(
|
||||
'test-receiver@example.com',
|
||||
'test-from-address@example.com',
|
||||
"Log Output: <br><pre>Build Log</pre>",
|
||||
"PHPCI - Test-Project - Passing Build",
|
||||
$actualMail
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedReturn, $returnValue);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::sendEmail
|
||||
*/
|
||||
|
@ -172,6 +229,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
|||
$expectedSubject,
|
||||
$actualMail)
|
||||
{
|
||||
if (! ($actualMail instanceof \Swift_Message)) {
|
||||
$type = is_object($actualMail) ? get_class($actualMail) : gettype($actualMail);
|
||||
throw new \Exception("Expected Swift_Message got " . $type);
|
||||
}
|
||||
$this->assertEquals(
|
||||
array($expectedFromAddress => null),
|
||||
$actualMail->getFrom()
|
||||
|
|
Loading…
Reference in a new issue