Remove duplicates from the list of recipients in the email plugin.
Closes #731
This commit is contained in:
parent
0be37b9e85
commit
353c4cafdb
|
@ -182,7 +182,7 @@ class Email implements \PHPCI\Plugin
|
||||||
$addresses[] = $this->options['default_mailto_address'];
|
$addresses[] = $this->options['default_mailto_address'];
|
||||||
return $addresses;
|
return $addresses;
|
||||||
}
|
}
|
||||||
return $addresses;
|
return array_unique($addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,6 +57,10 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getStatus')
|
->method('getStatus')
|
||||||
->will($this->returnValue(\PHPCI\Model\Build::STATUS_SUCCESS));
|
->will($this->returnValue(\PHPCI\Model\Build::STATUS_SUCCESS));
|
||||||
|
|
||||||
|
$this->mockBuild->expects($this->any())
|
||||||
|
->method('getCommitterEmail')
|
||||||
|
->will($this->returnValue("committer@test.com"));
|
||||||
|
|
||||||
$this->mockCiBuilder = $this->getMock(
|
$this->mockCiBuilder = $this->getMock(
|
||||||
'\PHPCI\Builder',
|
'\PHPCI\Builder',
|
||||||
array(
|
array(
|
||||||
|
@ -151,8 +155,53 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expectedReturn, $returnValue);
|
$this->assertEquals($expectedReturn, $returnValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers PHPUnit::execute
|
||||||
|
*/
|
||||||
|
public function testExecute_UniqueRecipientsFromWithCommitter()
|
||||||
|
{
|
||||||
|
$this->loadEmailPluginWithOptions(
|
||||||
|
array(
|
||||||
|
'addresses' => array('test-receiver@example.com', 'test-receiver2@example.com')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$actualMails = [];
|
||||||
|
$this->catchMailPassedToSend($actualMails);
|
||||||
|
|
||||||
|
$returnValue = $this->testedEmailPlugin->execute();
|
||||||
|
$this->assertTrue($returnValue);
|
||||||
|
|
||||||
|
$this->assertCount(2, $actualMails);
|
||||||
|
|
||||||
|
$actualTos = array(key($actualMails[0]->getTo()), key($actualMails[1]->getTo()));
|
||||||
|
$this->assertContains('test-receiver@example.com', $actualTos);
|
||||||
|
$this->assertContains('test-receiver2@example.com', $actualTos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers PHPUnit::execute
|
||||||
|
*/
|
||||||
|
public function testExecute_UniqueRecipientsWithCommiter()
|
||||||
|
{
|
||||||
|
$this->loadEmailPluginWithOptions(
|
||||||
|
array(
|
||||||
|
'commiter' => true,
|
||||||
|
'addresses' => array('test-receiver@example.com', 'committer@test.com')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$actualMails = [];
|
||||||
|
$this->catchMailPassedToSend($actualMails);
|
||||||
|
|
||||||
|
$returnValue = $this->testedEmailPlugin->execute();
|
||||||
|
$this->assertTrue($returnValue);
|
||||||
|
|
||||||
|
$actualTos = array(key($actualMails[0]->getTo()), key($actualMails[1]->getTo()));
|
||||||
|
$this->assertContains('test-receiver@example.com', $actualTos);
|
||||||
|
$this->assertContains('committer@test.com', $actualTos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,12 +264,16 @@ class EmailTest extends \PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
protected function catchMailPassedToSend(&$actualMail)
|
protected function catchMailPassedToSend(&$actualMail)
|
||||||
{
|
{
|
||||||
$this->mockMailer->expects($this->once())
|
$this->mockMailer->expects(is_array($actualMail) ? $this->atLeast(1) : $this->once())
|
||||||
->method('send')
|
->method('send')
|
||||||
->will(
|
->will(
|
||||||
$this->returnCallback(
|
$this->returnCallback(
|
||||||
function ($passedMail) use (&$actualMail) {
|
function ($passedMail) use (&$actualMail) {
|
||||||
$actualMail = $passedMail;
|
if(is_array($actualMail)) {
|
||||||
|
$actualMail[] = $passedMail;
|
||||||
|
} else {
|
||||||
|
$actualMail = $passedMail;
|
||||||
|
}
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue