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

View file

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