From 03a81a3283d73ae55bf98c79e7b29075dc10643c Mon Sep 17 00:00:00 2001 From: meadsteve Date: Mon, 25 Nov 2013 21:19:48 +0000 Subject: [PATCH 01/10] fix whitespace. --- Tests/PHPCI/Plugin/EmailTest.php | 186 +++++++++++----------- Tests/PHPCI/Plugin/PHPUnitTest.php | 240 +++++++++++++++-------------- 2 files changed, 225 insertions(+), 201 deletions(-) diff --git a/Tests/PHPCI/Plugin/EmailTest.php b/Tests/PHPCI/Plugin/EmailTest.php index 1343068c..1899c99c 100644 --- a/Tests/PHPCI/Plugin/EmailTest.php +++ b/Tests/PHPCI/Plugin/EmailTest.php @@ -1,32 +1,33 @@ 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( diff --git a/Tests/PHPCI/Plugin/PHPUnitTest.php b/Tests/PHPCI/Plugin/PHPUnitTest.php index 5809ac67..dec0dd3f 100644 --- a/Tests/PHPCI/Plugin/PHPUnitTest.php +++ b/Tests/PHPCI/Plugin/PHPUnitTest.php @@ -1,71 +1,73 @@ 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(); + } } \ No newline at end of file From a2c25d2d8f30868b0a29264f1886268cc0dc0544 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Mon, 25 Nov 2013 21:30:10 +0000 Subject: [PATCH 02/10] fix builder mocking --- Tests/PHPCI/Plugin/EmailTest.php | 2 +- Tests/PHPCI/Plugin/PHPUnitTest.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Tests/PHPCI/Plugin/EmailTest.php b/Tests/PHPCI/Plugin/EmailTest.php index 1899c99c..84618001 100644 --- a/Tests/PHPCI/Plugin/EmailTest.php +++ b/Tests/PHPCI/Plugin/EmailTest.php @@ -66,7 +66,7 @@ class EmailTest extends \PHPUnit_Framework_TestCase 'log' ), array(), - "mockBuilder", + "mockBuilder_email", false ); diff --git a/Tests/PHPCI/Plugin/PHPUnitTest.php b/Tests/PHPCI/Plugin/PHPUnitTest.php index dec0dd3f..e135cb81 100644 --- a/Tests/PHPCI/Plugin/PHPUnitTest.php +++ b/Tests/PHPCI/Plugin/PHPUnitTest.php @@ -37,9 +37,9 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase { $this->mockCiBuilder = $this->getMock( '\PHPCI\Builder', - array('findBinary'), + array('findBinary', 'executeCommand'), array(), - "mockBuilder", + "mockBuilder_phpUnit", false ); $this->mockCiBuilder->buildPath = "/"; @@ -94,8 +94,7 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase * @covers PHPUnit::execute * @covers PHPUnit::runDir */ - public function testExecute_CallsExecuteCommandOnceWhenGivenStringDirectory( - ) + public function testExecute_CallsExecuteCommandOnceWhenGivenStringDirectory() { chdir('/'); From 080784adc5e8cae1abe9fe77e2d65aa7f6f5af63 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Mon, 25 Nov 2013 21:48:21 +0000 Subject: [PATCH 03/10] fix test expectations to be exact in phpunit --- Tests/PHPCI/Plugin/PHPUnitTest.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Tests/PHPCI/Plugin/PHPUnitTest.php b/Tests/PHPCI/Plugin/PHPUnitTest.php index e135cb81..211d06e2 100644 --- a/Tests/PHPCI/Plugin/PHPUnitTest.php +++ b/Tests/PHPCI/Plugin/PHPUnitTest.php @@ -134,19 +134,18 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase * @covers PHPUnit::execute * @covers PHPUnit::runDir */ - public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayDirectory( - ) + public function testExecute_CallsExecuteCommandManyTimesWhenGivenArrayDirectory() { chdir('/'); $this->loadPhpUnitWithOptions( array( - 'directory' => array(0, 1) + 'directory' => array("dir1", "dir2") ) ); - $this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); - $this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); + $this->expectFindBinaryToBeCalled($this->exactly(2)); + $this->expectExectuteCommandToBeCalled($this->exactly(2)); $returnValue = $this->testedPhpUnit->execute(); } @@ -161,12 +160,12 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase $this->loadPhpUnitWithOptions( array( - 'config' => array(0, 1) + 'config' => array("configfile1.xml", "configfile2.xml") ) ); - $this->mockCiBuilder->expects($this->at(0))->method("executeCommand"); - $this->mockCiBuilder->expects($this->at(1))->method("executeCommand"); + $this->expectFindBinaryToBeCalled($this->exactly(2)); + $this->expectExectuteCommandToBeCalled($this->exactly(2)); $returnValue = $this->testedPhpUnit->execute(); } From 6d5bceea16c00b7f8a1ba419d0dd005edb3f0b5b Mon Sep 17 00:00:00 2001 From: meadsteve Date: Mon, 25 Nov 2013 21:49:14 +0000 Subject: [PATCH 04/10] fix copy-paste mistake in phpunit plugin runDir() --- PHPCI/Plugin/PhpUnit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Plugin/PhpUnit.php b/PHPCI/Plugin/PhpUnit.php index 9b905fb6..fde1b2fa 100755 --- a/PHPCI/Plugin/PhpUnit.php +++ b/PHPCI/Plugin/PhpUnit.php @@ -128,7 +128,7 @@ class PhpUnit implements \PHPCI\Plugin protected function runDir($dirPath) { if (is_array($dirPath)) { - return $this->recurseArg($dirPath, array($this, "runConfigFile")); + return $this->recurseArg($dirPath, array($this, "runDir")); } else { $curdir = getcwd(); chdir($this->phpci->buildPath); From 4f1d81e6fde4f3f8d9876ad176ba8acd6c058268 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 28 Nov 2013 21:04:27 +0000 Subject: [PATCH 05/10] update loggerConfig constructor to take array by default to make unit testing simpler. --- PHPCI/Helper/LoggerConfig.php | 29 +++++++++++++++++++++-------- console | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/PHPCI/Helper/LoggerConfig.php b/PHPCI/Helper/LoggerConfig.php index 014805f2..1e130e1a 100644 --- a/PHPCI/Helper/LoggerConfig.php +++ b/PHPCI/Helper/LoggerConfig.php @@ -13,18 +13,31 @@ class LoggerConfig { private $config; /** - * The file specified is expected to return an array. Where each key - * is the name of a logger. The value of each key should be an array or - * a function that returns an array of LogHandlers. - * @param $logConfigFilePath + * The filepath is expected to return an array which will be + * passed to the normal constructor. + * + * @param string $filePath + * @return LoggerConfig */ - function __construct($logConfigFilePath) { - if (file_exists($logConfigFilePath)) { - $this->config = require_once($logConfigFilePath); + public static function newFromFile($filePath) + { + if (file_exists($filePath)) { + $configArray = require($filePath); } else { - $this->config = array(); + $configArray = array(); } + return new self($configArray); + } + + /** + * Each key of the array is the name of a logger. The value of + * each key should be an array or a function that returns an + * array of LogHandlers. + * @param array $configArray + */ + function __construct(array $configArray = array()) { + $this->config = $configArray; } /** diff --git a/console b/console index 3358dce7..baa0e13a 100644 --- a/console +++ b/console @@ -20,7 +20,7 @@ use PHPCI\Command\DaemonCommand; use PHPCI\Command\PollCommand; use Symfony\Component\Console\Application; -$loggerConfig = new \PHPCI\Helper\LoggerConfig(__DIR__ . "/loggerconfig.php"); +$loggerConfig = \PHPCI\Helper\LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); $application = new Application(); From f1052443ab18ab6a0772a85decd7398e1d234cb0 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 28 Nov 2013 21:17:01 +0000 Subject: [PATCH 06/10] add basic type checking for LoggerConfig::GetFor --- Tests/PHPCI/Helper/LoggerConfigTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Tests/PHPCI/Helper/LoggerConfigTest.php diff --git a/Tests/PHPCI/Helper/LoggerConfigTest.php b/Tests/PHPCI/Helper/LoggerConfigTest.php new file mode 100644 index 00000000..a18f504a --- /dev/null +++ b/Tests/PHPCI/Helper/LoggerConfigTest.php @@ -0,0 +1,19 @@ +getFor("something"); + $this->assertInstanceOf('\Psr\Log\LoggerInterface', $logger); + } + + public function testGetFor_ReturnsMonologInstance() + { + $config = new \PHPCI\Helper\LoggerConfig(array()); + $logger = $config->getFor("something"); + $this->assertInstanceOf('\Monolog\Logger', $logger); + } +} + \ No newline at end of file From c8dc8a67b7e70a283f6196d9b53deb0fb85ff465 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 28 Nov 2013 21:18:11 +0000 Subject: [PATCH 07/10] Fix casing in LoggerConfig. --- PHPCI/Helper/LoggerConfig.php | 2 +- console | 8 ++++---- phpci.yml | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/PHPCI/Helper/LoggerConfig.php b/PHPCI/Helper/LoggerConfig.php index 1e130e1a..de1b2a67 100644 --- a/PHPCI/Helper/LoggerConfig.php +++ b/PHPCI/Helper/LoggerConfig.php @@ -46,7 +46,7 @@ class LoggerConfig { * @param $name * @return Logger */ - public function GetFor($name) { + public function getFor($name) { $handlers = $this->getHandlers(self::KEY_AlwaysLoaded); $handlers = array_merge($handlers, $this->getHandlers($name)); return new Logger($name, $handlers); diff --git a/console b/console index baa0e13a..f855f5ab 100644 --- a/console +++ b/console @@ -24,11 +24,11 @@ $loggerConfig = \PHPCI\Helper\LoggerConfig::newFromFile(__DIR__ . "/loggerconfig $application = new Application(); -$application->add(new RunCommand($loggerConfig->GetFor('RunCommand'))); +$application->add(new RunCommand($loggerConfig->getFor('RunCommand'))); $application->add(new InstallCommand); -$application->add(new UpdateCommand($loggerConfig->GetFor('UpdateCommand'))); +$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand'))); $application->add(new GenerateCommand); -$application->add(new DaemonCommand($loggerConfig->GetFor('DaemonCommand'))); -$application->add(new PollCommand($loggerConfig->GetFor('PollCommand'))); +$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand'))); +$application->add(new PollCommand($loggerConfig->getFor('PollCommand'))); $application->run(); diff --git a/phpci.yml b/phpci.yml index 42b2dba3..52b13952 100644 --- a/phpci.yml +++ b/phpci.yml @@ -2,7 +2,6 @@ build_settings: verbose: false ignore: - "vendor" - - "Tests" - "PHPCI/Command" # PHPMD complains about un-used parameters, but they are required. - "public/install.php" # PHPCS really doesn't like PHP mixed with HTML (and so it shouldn't) irc: @@ -13,14 +12,15 @@ build_settings: test: php_mess_detector: - php_code_sniffer: - standard: "PSR2" - php_loc: +phpunit: + directory: + "Tests/" -success: - irc: - message: "Build Success. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" -failure: - irc: - message: "Build Failed. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" \ No newline at end of file +#success: +# irc: +# message: "Build Success. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" + +#failure: +# irc: +# message: "Build Failed. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" \ No newline at end of file From ee9871e4a8e8b10bf4abee1878f514eb2db5cec8 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 28 Nov 2013 21:36:56 +0000 Subject: [PATCH 08/10] add tests to LoggerConfig for handler attaching. --- Tests/PHPCI/Helper/LoggerConfigTest.php | 60 ++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/Tests/PHPCI/Helper/LoggerConfigTest.php b/Tests/PHPCI/Helper/LoggerConfigTest.php index a18f504a..95ea3d62 100644 --- a/Tests/PHPCI/Helper/LoggerConfigTest.php +++ b/Tests/PHPCI/Helper/LoggerConfigTest.php @@ -1,19 +1,75 @@ getFor("something"); $this->assertInstanceOf('\Psr\Log\LoggerInterface', $logger); } public function testGetFor_ReturnsMonologInstance() { - $config = new \PHPCI\Helper\LoggerConfig(array()); + $config = new LoggerConfig(array()); $logger = $config->getFor("something"); $this->assertInstanceOf('\Monolog\Logger', $logger); } + + public function testGetFor_AttachesAlwaysPresentHandlers() + { + $expectedHandler = new Monolog\Handler\NullHandler(); + $config = new LoggerConfig(array( + LoggerConfig::KEY_AlwaysLoaded => function() use ($expectedHandler) { + return array($expectedHandler); + } + )); + + /** @var \Monolog\Logger $logger */ + $logger = $config->getFor("something"); + $actualHandler = $logger->popHandler(); + + $this->assertEquals($expectedHandler, $actualHandler); + } + + public function testGetFor_AttachesSpecificHandlers() + { + $expectedHandler = new Monolog\Handler\NullHandler(); + $config = new LoggerConfig(array( + "Specific" => function() use ($expectedHandler) { + return array($expectedHandler); + } + )); + + /** @var \Monolog\Logger $logger */ + $logger = $config->getFor("Specific"); + $actualHandler = $logger->popHandler(); + + $this->assertSame($expectedHandler, $actualHandler); + } + + public function testGetFor_IgnoresAlternativeHandlers() + { + $expectedHandler = new Monolog\Handler\NullHandler(); + $alternativeHandler = new Monolog\Handler\NullHandler(); + + $config = new LoggerConfig(array( + "Specific" => function() use ($expectedHandler) { + return array($expectedHandler); + }, + "Other" => function() use ($alternativeHandler) { + return array($alternativeHandler); + } + )); + + /** @var \Monolog\Logger $logger */ + $logger = $config->getFor("Specific"); + $actualHandler = $logger->popHandler(); + + $this->assertSame($expectedHandler, $actualHandler); + $this->assertNotSame($alternativeHandler, $actualHandler); + } } \ No newline at end of file From 4b16077428e8e67f3af720feac5406694076a4dd Mon Sep 17 00:00:00 2001 From: meadsteve Date: Fri, 29 Nov 2013 10:12:22 +0000 Subject: [PATCH 09/10] revert accidental change to phpci.yml --- phpci.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phpci.yml b/phpci.yml index 52b13952..42b2dba3 100644 --- a/phpci.yml +++ b/phpci.yml @@ -2,6 +2,7 @@ build_settings: verbose: false ignore: - "vendor" + - "Tests" - "PHPCI/Command" # PHPMD complains about un-used parameters, but they are required. - "public/install.php" # PHPCS really doesn't like PHP mixed with HTML (and so it shouldn't) irc: @@ -12,15 +13,14 @@ build_settings: test: php_mess_detector: -phpunit: - directory: - "Tests/" + php_code_sniffer: + standard: "PSR2" + php_loc: +success: + irc: + message: "Build Success. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" -#success: -# irc: -# message: "Build Success. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" - -#failure: -# irc: -# message: "Build Failed. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" \ No newline at end of file +failure: + irc: + message: "Build Failed. %PROJECT_TITLE% - %COMMIT% - %BUILD_URI%" \ No newline at end of file From 52a908009da5f474912d71e88a896fd10bdee6ef Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Fri, 6 Dec 2013 15:17:17 +0000 Subject: [PATCH 10/10] fix PhpUnit test caseing. --- Tests/PHPCI/Plugin/PHPUnitTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/PHPCI/Plugin/PHPUnitTest.php b/Tests/PHPCI/Plugin/PHPUnitTest.php index 211d06e2..89b24694 100644 --- a/Tests/PHPCI/Plugin/PHPUnitTest.php +++ b/Tests/PHPCI/Plugin/PHPUnitTest.php @@ -9,7 +9,7 @@ namespace PHPCI\Plugin\Tests; -use PHPCI\Plugin\PHPUnit; +use PHPCI\Plugin\PhpUnit; /** * Unit test for the PHPUnit plugin. @@ -19,7 +19,7 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase { /** - * @var PHPUnit $testedPhpUnit + * @var PhpUnit $testedPhpUnit */ protected $testedPhpUnit; @@ -57,7 +57,7 @@ class PHPUnitTest extends \PHPUnit_Framework_TestCase protected function loadPhpUnitWithOptions($arrOptions = array()) { - $this->testedPhpUnit = new PHPUnit($this->mockCiBuilder, $this->mockBuild, $arrOptions); + $this->testedPhpUnit = new PhpUnit($this->mockCiBuilder, $this->mockBuild, $arrOptions); } /**