From a324c7a794bdbdb2f61a5934018a7d097b4539a2 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 29 Dec 2013 00:29:25 +0100 Subject: [PATCH] QA: Use new unittest coding standards --- .../logging/LogCategoryTest.class.php | 184 +++++------------- 1 file changed, 44 insertions(+), 140 deletions(-) diff --git a/src/test/php/net/xp_framework/unittest/logging/LogCategoryTest.class.php b/src/test/php/net/xp_framework/unittest/logging/LogCategoryTest.class.php index de0e68975f..23756f09f8 100644 --- a/src/test/php/net/xp_framework/unittest/logging/LogCategoryTest.class.php +++ b/src/test/php/net/xp_framework/unittest/logging/LogCategoryTest.class.php @@ -16,7 +16,6 @@ class LogCategoryTest extends TestCase { /** * Setup method. Creates logger and cat member for easier access to * the Logger instance - * */ public function setUp() { $this->cat= new \util\log\LogCategory('test'); @@ -45,8 +44,8 @@ public function append(LoggingEvent $event) { /** * Helper method * - * @param string method - * @param mixed[] args default ["Argument"] + * @param string $method + * @param var $func A function to be called with `$this->cat` as argument * @throws unittest.AssertionFailedError */ protected function assertLogged($result, $func) { @@ -55,74 +54,50 @@ protected function assertLogged($result, $func) { $this->assertEquals($result, $app->messages); } - /** - * Ensure the logger category initially has no appenders - * - */ #[@test] - public function initiallyNoAppenders() { + public function logger_category_initially_has_no_appenders() { $this->assertFalse($this->cat->hasAppenders()); } - /** - * Tests adding an appender returns the added appender - * - */ #[@test] - public function addAppenderReturnsAddedAppender() { + public function addAappender_returns_added_appender() { $appender= $this->mockAppender(); $this->assertEquals($appender, $this->cat->addAppender($appender)); } - /** - * Tests adding an appender returns the log category - * - */ #[@test] - public function withAppenderReturnsCategory() { + public function withAppender_returns_category() { $this->assertEquals($this->cat, $this->cat->withAppender($this->mockAppender())); } - /** - * Tests hasAppenders() and addAppender() methods - * - */ #[@test] - public function hasAppendersAfterAdding() { + public function hasAppenders_initially_returns_false() { + $this->assertFalse($this->cat->hasAppenders()); + } + + #[@test] + public function hasAppenders_returns_true_after_adding_an_appender() { $this->cat->addAppender($this->mockAppender()); $this->assertTrue($this->cat->hasAppenders()); } - /** - * Tests hasAppenders() and removeAppender() methods - * - */ #[@test] - public function hasNoMoreAppendersAfterRemoving() { + public function hasAppenders_returns_false_after_removing_added_appender() { $a= $this->cat->addAppender($this->mockAppender()); $this->cat->removeAppender($a); $this->assertFalse($this->cat->hasAppenders()); } - /** - * Tests addAppender() method - * - */ #[@test] - public function addAppenderTwice() { + public function adding_appender_twice_with_same_flags_has_no_effect() { $a= $this->mockAppender(); $this->cat->addAppender($a); $this->cat->addAppender($a); - $this->cat->removeAppender($a); - $this->assertFalse($this->cat->hasAppenders()); + $this->assertEquals(array($a), $this->cat->getAppenders()); } - /** - * Tests addAppender() and removeAppender() methods - * - */ #[@test] - public function addAppenderTwiceWithDifferentFlags() { + public function adding_appender_twice_with_differing_flags() { $a= $this->mockAppender(); $this->cat->addAppender($a, \util\log\LogLevel::INFO); $this->cat->addAppender($a, \util\log\LogLevel::WARN); @@ -132,40 +107,26 @@ public function addAppenderTwiceWithDifferentFlags() { $this->assertFalse($this->cat->hasAppenders()); } - /** - * Tests adding an appender sets default layout if appender does not - * have a layout. - * - */ #[@test] - public function addAppenderSetsDefaultLayout() { + public function addAppender_sets_layout_if_appender_does_not_have_layout() { $appender= newinstance('util.log.Appender', array(), '{ public function append(LoggingEvent $event) { } }'); $this->cat->addAppender($appender); - $this->assertClass($appender->getLayout(), 'util.log.layout.DefaultLayout'); + $this->assertInstanceOf('util.log.layout.DefaultLayout', $appender->getLayout()); } - /** - * Tests adding an appender does not overwrite layout - * - */ #[@test] - public function addAppenderDoesNotOverwriteLayout() { + public function addAppender_does_not_overwrite_layout() { $appender= newinstance('util.log.Appender', array(), '{ public function append(LoggingEvent $event) { } }'); $this->cat->addAppender($appender->withLayout(new PatternLayout('%m'))); - $this->assertClass($appender->getLayout(), 'util.log.layout.PatternLayout'); + $this->assertInstanceOf('util.log.layout.PatternLayout', $appender->getLayout()); } - /** - * Tests adding an appender sets default layout if appender does not - * have a layout. - * - */ #[@test] - public function withAppenderSetsLayout() { + public function withAppender_sets_layout_if_appender_does_not_have_layout() { $appender= newinstance('util.log.Appender', array(), '{ public function append(LoggingEvent $event) { } }'); @@ -173,46 +134,30 @@ public function append(LoggingEvent $event) { } $this->assertClass($appender->getLayout(), 'util.log.layout.DefaultLayout'); } - /** - * Tests adding an appender does not overwrite layout - * - */ #[@test] - public function withAppenderDoesNotOverwriteLayout() { + public function withAppender_does_not_overwrite_layout() { $appender= newinstance('util.log.Appender', array(), '{ public function append(LoggingEvent $event) { } }'); $this->cat->withAppender($appender->withLayout(new PatternLayout('%m'))); - $this->assertClass($appender->getLayout(), 'util.log.layout.PatternLayout'); + $this->assertInstanceOf('util.log.layout.PatternLayout', $appender->getLayout()); } - /** - * Tests equals() method - * - */ #[@test] - public function logCategoriesWithSameIdentifierAreEqual() { + public function log_categories_with_same_identifiers_are_equal() { $this->assertEquals(new \util\log\LogCategory('test'), $this->cat); } - /** - * Tests equals() method - * - */ #[@test] - public function logCategoriesDifferingAppendersNotEqual() { + public function log_categories_with_differing_appenders_are_not_equal() { $this->assertNotEquals( new \util\log\LogCategory('test'), $this->cat->withAppender($this->mockAppender()) ); } - /** - * Tests equals() method - * - */ #[@test] - public function logCategoriesAppendersDifferingInFlagsNotEqual() { + public function log_categories_with_appenders_differing_in_flags_are_not_equal() { $appender= $this->mockAppender(); $this->assertNotEquals( create(new \util\log\LogCategory('test'))->withAppender($appender, \util\log\LogLevel::WARN), @@ -220,12 +165,8 @@ public function logCategoriesAppendersDifferingInFlagsNotEqual() { ); } - /** - * Tests equals() method - * - */ #[@test] - public function logCategoriesSameAppendersEqual() { + public function log_categories_with_same_appenders_are_equal() { $appender= $this->mockAppender(); $this->assertEquals( create(new \util\log\LogCategory('test'))->withAppender($appender), @@ -313,12 +254,8 @@ function($cat) { $cat->log(LogLevel::INFO, array('Test', '123')); } ); } - /** - * Tests flags - * - */ #[@test] - public function warningMessageOnlyGetsAppendedToWarnAppender() { + public function warning_message_only_gets_appended_to_warn_appender() { $app1= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::INFO); $app2= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::WARN); $this->cat->warn('Test'); @@ -326,72 +263,44 @@ public function warningMessageOnlyGetsAppendedToWarnAppender() { $this->assertEquals(array(array('warn', 'Test')), $app2->messages); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getAppenders() { + public function getAppenders_initially_returns_empty_array() { + $this->assertEquals(array(), $this->cat->getAppenders()); + } + + #[@test] + public function getAppenders_returns_added_appender() { $appender= $this->mockAppender(); $this->cat->addAppender($appender); $this->assertEquals(array($appender), $this->cat->getAppenders()); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getAppendersWithoutAppendersAdded() { - $this->assertEquals(array(), $this->cat->getAppenders()); - } - - /** - * Tests getAppenders() - * - */ - #[@test] - public function getAllAppendersWhenErrorLevelAppenderExists() { + public function getAppenders_returns_added_appender_with_error_flags() { $appender= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::ERROR); $this->assertEquals(array($appender), $this->cat->getAppenders()); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getErrorLevelAppendersWhenErrorLevelAppendersExist() { + public function getAppenders_with_error_flags_returns_added_appender_with_error_flags() { $appender= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::ERROR); $this->assertEquals(array($appender), $this->cat->getAppenders(\util\log\LogLevel::ERROR)); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getInfoLevelAppendersWhenOnlyErrorLevelAppendersExist() { + public function getAppenders_with_info_flags_does_not_return_added_appender_with_error_flags() { $appender= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::ERROR); $this->assertEquals(array(), $this->cat->getAppenders(\util\log\LogLevel::INFO)); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getInfoLevelAppendersWhenErrorAndInfoLevelAppenderExists() { + public function getAppenders_with_info_flags_returns_added_appender_with_info_and_error_flags() { $appender= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::ERROR | \util\log\LogLevel::INFO); $this->assertEquals(array($appender), $this->cat->getAppenders(\util\log\LogLevel::INFO)); } - /** - * Tests getAppenders() - * - */ #[@test] - public function getAllAppenders() { + public function getAppenders_returns_appenders_with_flags() { $app1= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::ERROR); $app2= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::WARN); $app3= $this->cat->addAppender($this->mockAppender(), \util\log\LogLevel::INFO); @@ -399,24 +308,19 @@ public function getAllAppenders() { $this->assertEquals(array($app1, $app2, $app3, $app4), $this->cat->getAppenders()); } - - /** - * Tests LogCategory::hasContext() - * - */ #[@test] - public function hasContext() { + public function hasContext_initially_returns_false() { $this->assertFalse($this->cat->hasContext()); + } + + #[@test] + public function hasContext_returns_true_after_setting_context() { $this->cat->setContext(new NestedLogContext()); $this->assertTrue($this->cat->hasContext()); } - /** - * Tests LogCategory::getContext() - * - */ #[@test] - public function getContext() { + public function getContext_returns_context_previously_set_with_setContext() { $context= new NestedLogContext(); $this->cat->setContext($context); $this->assertEquals($context, $this->cat->getContext());