fix whitespace.

This commit is contained in:
meadsteve 2013-11-25 21:19:48 +00:00
parent 477fd58641
commit 03a81a3283
2 changed files with 225 additions and 201 deletions

View file

@ -1,32 +1,33 @@
<?php <?php
/** /**
* PHPCI - Continuous Integration for PHP * PHPCI - Continuous Integration for PHP
* *
* @copyright Copyright 2013, Block 8 Limited. * @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md * @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/ * @link http://www.phptesting.org/
*/ */
namespace PHPCI\Plugin\Tests; namespace PHPCI\Plugin\Tests;
use PHPCI\Plugin\Email as EmailPlugin; use PHPCI\Plugin\Email as EmailPlugin;
/** /**
* Unit test for the PHPUnit plugin. * Unit test for the PHPUnit plugin.
* @author meadsteve * @author meadsteve
*/ */
class EmailTest extends \PHPUnit_Framework_TestCase class EmailTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var EmailPlugin $testedPhpUnit * @var EmailPlugin $testedPhpUnit
*/ */
protected $testedEmailPlugin; protected $testedEmailPlugin;
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder * @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder
*/ */
protected $mockCiBuilder; protected $mockCiBuilder;
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject $mockMailer * @var \PHPUnit_Framework_MockObject_MockObject $mockMailer
@ -38,15 +39,15 @@ class EmailTest extends \PHPUnit_Framework_TestCase
*/ */
protected $mockBuild; protected $mockBuild;
public function setUp() public function setUp()
{ {
$this->mockBuild = $this->getMock( $this->mockBuild = $this->getMock(
'\PHPCI\Model\Build', '\PHPCI\Model\Build',
array('getLog', 'getStatus'), array('getLog', 'getStatus'),
array(), array(),
"mockBuild", "mockBuild",
false false
); );
$this->mockBuild->expects($this->any()) $this->mockBuild->expects($this->any())
->method('getLog') ->method('getLog')
@ -56,27 +57,33 @@ 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->mockCiBuilder = $this->getMock( $this->mockCiBuilder = $this->getMock(
'\PHPCI\Builder', '\PHPCI\Builder',
array('getSystemConfig', array(
'getBuildProjectTitle', 'getSystemConfig',
'getBuild', 'getBuildProjectTitle',
'log'), 'getBuild',
array(), 'log'
"mockBuilder", ),
false array(),
); "mockBuilder",
false
);
$this->mockCiBuilder->buildPath = "/"; $this->mockCiBuilder->buildPath = "/";
$this->mockCiBuilder->expects($this->any()) $this->mockCiBuilder->expects($this->any())
->method('getSystemConfig') ->method('getSystemConfig')
->with('phpci') ->with('phpci')
->will($this->returnValue(array( ->will(
'email_settings' => array( $this->returnValue(
'from_address' => "test-from-address@example.com" array(
'email_settings' => array(
'from_address' => "test-from-address@example.com"
)
)
) )
))); );
$this->mockCiBuilder->expects($this->any()) $this->mockCiBuilder->expects($this->any())
->method('getBuildProjectTitle') ->method('getBuildProjectTitle')
->will($this->returnValue('Test-Project')); ->will($this->returnValue('Test-Project'));
@ -85,53 +92,55 @@ class EmailTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->mockBuild)); ->will($this->returnValue($this->mockBuild));
$this->mockMailer = $this->getMock( $this->mockMailer = $this->getMock(
'\Swift_Mailer', '\Swift_Mailer',
array('send'), array('send'),
array(), array(),
"mockMailer", "mockMailer",
false false
); );
$this->loadEmailPluginWithOptions(); $this->loadEmailPluginWithOptions();
} }
protected function loadEmailPluginWithOptions($arrOptions = array()) protected function loadEmailPluginWithOptions($arrOptions = array())
{ {
$this->testedEmailPlugin = new EmailPlugin( $this->testedEmailPlugin = new EmailPlugin(
$this->mockCiBuilder, $this->mockCiBuilder,
$this->mockBuild, $this->mockBuild,
$this->mockMailer, $this->mockMailer,
$arrOptions $arrOptions
); );
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
*/ */
public function testExecute_ReturnsFalseWithoutArgs() public function testExecute_ReturnsFalseWithoutArgs()
{ {
$returnValue = $this->testedEmailPlugin->execute(); $returnValue = $this->testedEmailPlugin->execute();
// As no addresses will have been mailed as non are configured. // As no addresses will have been mailed as non are configured.
$expectedReturn = false; $expectedReturn = false;
$this->assertEquals($expectedReturn, $returnValue); $this->assertEquals($expectedReturn, $returnValue);
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
*/ */
public function testExecute_BuildsBasicEmails() public function testExecute_BuildsBasicEmails()
{ {
$this->loadEmailPluginWithOptions(array( $this->loadEmailPluginWithOptions(
'addresses' => array('test-receiver@example.com') array(
)); 'addresses' => array('test-receiver@example.com')
)
);
/** @var \Swift_Message $actualMail */ /** @var \Swift_Message $actualMail */
$actualMail = null; $actualMail = null;
$this->catchMailPassedToSend($actualMail); $this->catchMailPassedToSend($actualMail);
$returnValue = $this->testedEmailPlugin->execute(); $returnValue = $this->testedEmailPlugin->execute();
$expectedReturn = true; $expectedReturn = true;
$this->assertSystemMail( $this->assertSystemMail(
'test-receiver@example.com', 'test-receiver@example.com',
@ -141,14 +150,14 @@ class EmailTest extends \PHPUnit_Framework_TestCase
$actualMail $actualMail
); );
$this->assertEquals($expectedReturn, $returnValue); $this->assertEquals($expectedReturn, $returnValue);
} }
/** /**
* @covers PHPUnit::sendEmail * @covers PHPUnit::sendEmail
*/ */
public function testSendEmail_CallsMailerSend() public function testSendEmail_CallsMailerSend()
{ {
$this->mockMailer->expects($this->once()) $this->mockMailer->expects($this->once())
@ -157,8 +166,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers PHPUnit::sendEmail * @covers PHPUnit::sendEmail
*/ */
public function testSendEmail_BuildsAMessageObject() public function testSendEmail_BuildsAMessageObject()
{ {
$subject = "Test mail"; $subject = "Test mail";
@ -172,8 +181,8 @@ class EmailTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @covers PHPUnit::sendEmail * @covers PHPUnit::sendEmail
*/ */
public function testSendEmail_BuildsExpectedMessage() public function testSendEmail_BuildsExpectedMessage()
{ {
$subject = "Test mail"; $subject = "Test mail";
@ -200,7 +209,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @param \Swift_Message $actualMail passed by ref and populated with * @param \Swift_Message $actualMail passed by ref and populated with
* the message object the mock mailer * the message object the mock mailer
* receives. * receives.
*/ */
@ -227,14 +236,17 @@ class EmailTest extends \PHPUnit_Framework_TestCase
* @param string $expectedSubject * @param string $expectedSubject
* @param \Swift_Message $actualMail * @param \Swift_Message $actualMail
*/ */
protected function assertSystemMail($expectedToAddress, protected function assertSystemMail(
$expectedFromAddress, $expectedToAddress,
$expectedBody, $expectedFromAddress,
$expectedSubject, $expectedBody,
$actualMail) $expectedSubject,
{ $actualMail
if (! ($actualMail instanceof \Swift_Message)) { ) {
$type = is_object($actualMail) ? get_class($actualMail) : gettype($actualMail); if (!($actualMail instanceof \Swift_Message)) {
$type = is_object($actualMail) ? get_class($actualMail) : gettype(
$actualMail
);
throw new \Exception("Expected Swift_Message got " . $type); throw new \Exception("Expected Swift_Message got " . $type);
} }
$this->assertEquals( $this->assertEquals(

View file

@ -1,71 +1,73 @@
<?php <?php
/** /**
* PHPCI - Continuous Integration for PHP * PHPCI - Continuous Integration for PHP
* *
* @copyright Copyright 2013, Block 8 Limited. * @copyright Copyright 2013, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md * @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/ * @link http://www.phptesting.org/
*/ */
namespace PHPCI\Plugin\Tests; namespace PHPCI\Plugin\Tests;
use PHPCI\Plugin\PHPUnit; use PHPCI\Plugin\PHPUnit;
/** /**
* Unit test for the PHPUnit plugin. * Unit test for the PHPUnit plugin.
* @author meadsteve * @author meadsteve
*/ */
class PHPUnitTest extends \PHPUnit_Framework_TestCase class PHPUnitTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
* @var PHPUnit $testedPhpUnit * @var PHPUnit $testedPhpUnit
*/ */
protected $testedPhpUnit; protected $testedPhpUnit;
/**
* @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder
*/
protected $mockCiBuilder;
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder * @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder
*/ */
protected $mockBuild; protected $mockCiBuilder;
public function setUp() /**
{ * @var \PHPUnit_Framework_MockObject_MockObject $mockCiBuilder
$this->mockCiBuilder = $this->getMock( */
'\PHPCI\Builder', protected $mockBuild;
array(),
array(), public function setUp()
"mockBuilder", {
false $this->mockCiBuilder = $this->getMock(
); '\PHPCI\Builder',
$this->mockCiBuilder->buildPath = "/"; array('findBinary'),
array(),
"mockBuilder",
false
);
$this->mockCiBuilder->buildPath = "/";
$this->mockBuild = $this->getMock( $this->mockBuild = $this->getMock(
'\PHPCI\Model\Build', '\PHPCI\Model\Build',
array(), array(),
array(), array(),
"MockBuild", "MockBuild",
false false
); );
$this->loadPhpUnitWithOptions(); $this->loadPhpUnitWithOptions();
} }
protected function loadPhpUnitWithOptions($arrOptions = array()) protected function loadPhpUnitWithOptions($arrOptions = array())
{ {
$this->testedPhpUnit = new PHPUnit($this->mockCiBuilder,$this->mockBuild, $arrOptions); $this->testedPhpUnit = new PHPUnit($this->mockCiBuilder, $this->mockBuild, $arrOptions);
} }
/** /**
* @param \PHPUnit_Framework_MockObject_Matcher_Invocation $expectation * @param \PHPUnit_Framework_MockObject_Matcher_Invocation $expectation
*/ */
protected function expectFindBinaryToBeCalled($expectation) { protected function expectFindBinaryToBeCalled($expectation)
{
$this->mockCiBuilder->expects($expectation) $this->mockCiBuilder->expects($expectation)
->method("findBinary") ->method("findBinary")
->will($this->returnValue("phpunit")); ->will($this->returnValue("phpunit"));
} }
/** /**
@ -74,89 +76,99 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase
public function expectExectuteCommandToBeCalled($expectation) public function expectExectuteCommandToBeCalled($expectation)
{ {
$this->mockCiBuilder->expects($expectation) $this->mockCiBuilder->expects($expectation)
->method("executeCommand"); ->method("executeCommand");
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
*/ */
public function testExecute_ReturnsTrueWithoutArgs() public function testExecute_ReturnsTrueWithoutArgs()
{ {
$returnValue = $this->testedPhpUnit->execute(); $returnValue = $this->testedPhpUnit->execute();
$expectedReturn = true; $expectedReturn = true;
$this->assertEquals($expectedReturn, $returnValue); $this->assertEquals($expectedReturn, $returnValue);
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
* @covers PHPUnit::runDir * @covers PHPUnit::runDir
*/ */
public function testExecute_CallsExecuteCommandOnceWhenGivenStringDirectory() public function testExecute_CallsExecuteCommandOnceWhenGivenStringDirectory(
{ )
chdir('/'); {
chdir('/');
$this->loadPhpUnitWithOptions(array( $this->loadPhpUnitWithOptions(
'directory' => "Fake/Test/Path" array(
)); 'directory' => "Fake/Test/Path"
)
$this->expectFindBinaryToBeCalled($this->once()); );
$this->expectExectuteCommandToBeCalled($this->once());
$returnValue = $this->testedPhpUnit->execute();
}
/**
* @covers PHPUnit::execute
* @covers PHPUnit::runConfigFile
*/
public function testExecute_CallsExecuteCommandOnceWhenGivenStringConfig()
{
chdir('/');
$this->loadPhpUnitWithOptions(array(
'config' => "Fake/Test/config.xml"
));
$this->expectFindBinaryToBeCalled($this->once()); $this->expectFindBinaryToBeCalled($this->once());
$this->expectExectuteCommandToBeCalled($this->once()); $this->expectExectuteCommandToBeCalled($this->once());
$returnValue = $this->testedPhpUnit->execute(); $returnValue = $this->testedPhpUnit->execute();
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
* @covers PHPUnit::runDir * @covers PHPUnit::runConfigFile
*/ */
public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayDirectory() public function testExecute_CallsExecuteCommandOnceWhenGivenStringConfig()
{ {
chdir('/'); chdir('/');
$this->loadPhpUnitWithOptions(array( $this->loadPhpUnitWithOptions(
'directory' => array(0, 1) array(
)); 'config' => "Fake/Test/config.xml"
)
);
$this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); $this->expectFindBinaryToBeCalled($this->once());
$this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); $this->expectExectuteCommandToBeCalled($this->once());
$returnValue = $this->testedPhpUnit->execute(); $returnValue = $this->testedPhpUnit->execute();
} }
/** /**
* @covers PHPUnit::execute * @covers PHPUnit::execute
* @covers PHPUnit::runConfigFile * @covers PHPUnit::runDir
*/ */
public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayConfig() public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayDirectory(
{ )
chdir('/'); {
chdir('/');
$this->loadPhpUnitWithOptions(array( $this->loadPhpUnitWithOptions(
'config' => array(0, 1) array(
)); 'directory' => array(0, 1)
)
);
$this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); $this->mockCiBuilder->expects($this->at(0))->method("executeCommand");
$this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); $this->mockCiBuilder->expects($this->at(1))->method("executeCommand");
$returnValue = $this->testedPhpUnit->execute(); $returnValue = $this->testedPhpUnit->execute();
} }
/**
* @covers PHPUnit::execute
* @covers PHPUnit::runConfigFile
*/
public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayConfig()
{
chdir('/');
$this->loadPhpUnitWithOptions(
array(
'config' => array(0, 1)
)
);
$this->mockCiBuilder->expects($this->at(0))->method("executeCommand");
$this->mockCiBuilder->expects($this->at(1))->method("executeCommand");
$returnValue = $this->testedPhpUnit->execute();
}
} }