logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1184770 [2/2] - in /logging/log4php/trunk/src: changes/ main/php/ main/php/appenders/ main/php/configurators/ main/php/helpers/ main/php/layouts/ test/php/ test/php/appenders/ test/php/configurators/ test/php/filters/ test/php/renderers/
Date Sun, 16 Oct 2011 07:12:51 GMT
Added: logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
(added)
+++ logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
Sun Oct 16 07:12:49 2011
@@ -0,0 +1,163 @@
+<?php
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *	   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @package log4php
+ */
+
+/**
+ * @group configurators
+ */
+class LoggerConfigurationAdapterXMLTest extends PHPUnit_Framework_TestCase {
+	
+	/** Expected output of parsing config1.xml.*/
+	private $expected1 = array(
+		'appenders' => array(
+			'default' => array(
+				'class' => 'LoggerAppenderEcho',
+				'layout' => array(
+					'class' => 'LoggerLayoutTTCC',
+				),
+				'filters' => array(
+					array(
+						'class' => 'LoggerFilterLevelRange',
+						'params' => array(
+							'levelMin' => 'ERROR',
+							'levelMax' => 'FATAL',
+							'acceptOnMatch' => 'false',
+						),
+					),
+					array(
+						'class' => 'LoggerFilterDenyAll',
+					),
+				),
+			),
+			'file' => array(
+				'class' => 'LoggerAppenderDailyFile',
+				'layout' => array(
+					'class' => 'LoggerLayoutPattern',
+					'params' => array(
+						'conversionPattern' => '%d{ISO8601} [%p] %c: %m (at %F line %L)%n',
+					),
+				),
+				'params' => array(
+					'datePattern' => 'Ymd',
+					'file' => 'target/examples/daily_%s.log',
+				),
+				'threshold' => 'warn'
+			),
+		),
+		'loggers' => array(
+			'foo.bar.baz' => array(
+				'level' => 'trace',
+				'additivity' => 'false',
+				'appenders' => array('default'),
+			),
+			'foo.bar' => array(
+				'level' => 'debug',
+				'additivity' => 'true',
+				'appenders' => array('file'),
+			),
+			'foo' => array(
+				'level' => 'warn',
+				'appenders' => array('default', 'file'),
+			),
+		),
+		'renderers' => array(
+			array(
+				'renderedClass' => 'Fruit',
+				'renderingClass' => 'FruitRenderer',
+			),
+			array(
+				'renderedClass' => 'Beer',
+				'renderingClass' => 'BeerRenderer',
+			),
+		),
+		'threshold' => 'debug',
+		'rootLogger' => array(
+			'level' => 'DEBUG',
+			'appenders' => array('default'),
+		),
+	);
+	
+	public function setUp() {
+		Logger::resetConfiguration();
+	}
+	
+	public function tearDown() {
+		Logger::resetConfiguration();
+	}
+	
+	public function testConversion() {
+		$url =  dirname(__FILE__) . '/config1.xml';
+		$adapter = new LoggerConfigurationAdapterXML();
+		$actual = $adapter->convert($url);
+		$this->assertEquals($this->expected1, $actual);
+	}
+	
+	/**
+	 * Test exception is thrown when file cannot be found.
+ 	 * @expectedException LoggerException
+ 	 * @expectedExceptionMessage File [you/will/never/find/me.conf] does not exist.
+	 */
+	public function testNonExistantFile() {
+		$adapter = new LoggerConfigurationAdapterXML();
+		$adapter->convert('you/will/never/find/me.conf');
+	}
+	
+	/**
+	 * Test exception is thrown when file contains invalid XML.
+	 * @ expectedException LoggerException
+	 * @ expectedExceptionMessage Cannot load config file
+	 */
+	public function testInvalidXMLFile() {
+		// TODO: fix error reporting for XML files
+		//$url =  dirname(__FILE__) . '/config4.xml';
+		//$adapter = new LoggerConfigurationAdapterXML();
+		//$adapter->convert($url);
+	}
+	
+	/**
+	 * Test that a warning is triggered when two loggers with the same name 
+	 * are defined.
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage log4php: Duplicate logger definition [foo]. Overwriting
+	 */
+	public function testDuplicateLoggerWarning() {
+		$url =  dirname(__FILE__) . '/config3.xml';
+		$adapter = new LoggerConfigurationAdapterXML();
+		$adapter->convert($url);
+	}
+	
+	
+	/**
+	 * Test that when two loggers with the same name are defined, the second 
+	 * one will overwrite the first.
+	 */
+	public function testDuplicateLoggerConfig() {
+		$url =  dirname(__FILE__) . '/config3.xml';
+		$adapter = new LoggerConfigurationAdapterXML();
+		
+		// Supress the warning so that test can continue 
+		$config = @$adapter->convert($url);
+
+		// Second definition of foo has level set to warn (the first to info)
+		$this->assertEquals('warn', $config['loggers']['foo']['level']);		
+	}
+}
+
+?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config1.ini
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config1.ini?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config1.ini (added)
+++ logging/log4php/trunk/src/test/php/configurators/config1.ini Sun Oct 16 07:12:49 2011
@@ -0,0 +1,24 @@
+log4php.rootLogger = DEBUG, default
+
+log4php.appender.default = LoggerAppenderEcho
+log4php.appender.default.layout = LoggerLayoutTTCC
+
+log4php.appender.file = LoggerAppenderDailyFile
+log4php.appender.file.layout = LoggerLayoutPattern
+log4php.appender.file.layout.conversionPattern =%d{ISO8601} [%p] %c: %m (at %F line %L)%n
+log4php.appender.file.datePattern = Ymd
+log4php.appender.file.file = target/examples/daily_%s.log
+log4php.appender.file.threshold = warn
+
+log4php.logger.foo = warn, default
+
+log4php.logger.foo.bar = debug, file
+log4php.additivity.foo.bar = true
+
+log4php.logger.foo.bar.baz = trace, default, file
+log4php.additivity.foo.bar.baz = false
+
+log4php.renderer.Fruit = FruitRenderer
+log4php.renderer.Beer = BeerRenderer
+
+log4php.threshold = debug

Added: logging/log4php/trunk/src/test/php/configurators/config1.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config1.php?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config1.php (added)
+++ logging/log4php/trunk/src/test/php/configurators/config1.php Sun Oct 16 07:12:49 2011
@@ -0,0 +1,19 @@
+<?php
+
+return array(
+	'rootLogger' => array(
+		'level' => 'info',
+		'appenders' => array('default')
+	),
+	'appenders' => array(
+		'default' => array(
+			'class' => 'LoggerAppenderEcho',
+			'layout' => array(
+				'class' => 'LoggerLayoutSimple'
+			 )
+		)
+	)
+)
+;
+
+?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config1.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config1.xml?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config1.xml (added)
+++ logging/log4php/trunk/src/test/php/configurators/config1.xml Sun Oct 16 07:12:49 2011
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration xmlns="http://logging.apache.org/log4php" threshold="debug">
+	<renderer renderedClass="Fruit" renderingClass="FruitRenderer" />
+	<renderer renderedClass="Beer" renderingClass="BeerRenderer" />
+    <appender name="default" class="LoggerAppenderEcho">
+        <layout class="LoggerLayoutTTCC"/>
+        <filter class="LoggerFilterLevelRange">
+            <param name="levelMin" value="ERROR" />
+            <param name="levelMax" value="FATAL" />
+            <param name="acceptOnMatch" value="false" />
+        </filter>
+        <filter class="LoggerFilterDenyAll" />
+    </appender>
+	<appender name="file" class="LoggerAppenderDailyFile" threshold="warn">
+		<param name="datePattern" value="Ymd" />
+		<param name="file" value="target/examples/daily_%s.log" />
+        <layout class="LoggerLayoutPattern">
+        	<param name="conversionPattern" value= "%d{ISO8601} [%p] %c: %m (at %F line %L)%n"
/>
+        </layout>
+    </appender>
+    <logger name="foo.bar.baz" additivity="false">
+        <level value="trace" />
+        <appender_ref ref="default" />
+    </logger>
+    <logger name="foo.bar" additivity="true">
+        <level value="debug" />
+        <appender_ref ref="file" />
+    </logger>
+    <logger name="foo">
+        <level value="warn" />
+        <appender_ref ref="default" />
+        <appender_ref ref="file" />
+    </logger>
+    <root>
+        <level value="DEBUG" />
+        <appender_ref ref="default" />
+    </root>
+</configuration>

Added: logging/log4php/trunk/src/test/php/configurators/config2.ini
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config2.ini?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config2.ini (added)
+++ logging/log4php/trunk/src/test/php/configurators/config2.ini Sun Oct 16 07:12:49 2011
@@ -0,0 +1,2 @@
+not a valid ini file ()
+ 

Added: logging/log4php/trunk/src/test/php/configurators/config2.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config2.php?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config2.php (added)
+++ logging/log4php/trunk/src/test/php/configurators/config2.php Sun Oct 16 07:12:49 2011
@@ -0,0 +1,20 @@
+<?php
+
+
+return array(
+	'rootLogger' => array(
+		'level' => 'info',
+		'appenders' => array('default')
+	),
+	'appenders' => array(
+		'default' => array(
+			'class' => 'LoggerAppenderEcho',
+			'layout' => array(
+				'class' => 'LoggerLayoutSimple'
+			 )
+		)
+	)
+
+// Invalid file - no closing brace.
+	
+?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config2.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config2.xml?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config2.xml (added)
+++ logging/log4php/trunk/src/test/php/configurators/config2.xml Sun Oct 16 07:12:49 2011
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+	<!-- Duplicate renderer -->
+	<renderer renderedClass="Fruit" renderingClass="FruitRenderer1" />
+	<renderer renderedClass="Fruit" renderingClass="FruitRenderer2" />
+	<renderer renderedClass="Beer" renderingClass="BeerRenderer" />
+    <appender name="default" class="LoggerAppenderEcho">
+        <layout class="LoggerLayoutSimple"/>
+    </appender>
+    <root>
+        <level value="DEBUG" />
+        <appender_ref ref="default" />
+    </root>
+</configuration>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config3.ini
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config3.ini?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config3.ini (added)
+++ logging/log4php/trunk/src/test/php/configurators/config3.ini Sun Oct 16 07:12:49 2011
@@ -0,0 +1,7 @@
+log4php.rootLogger = DEBUG, default
+
+log4php.appender.default = LoggerAppenderEcho
+
+# invalid appender line should trigger warning
+log4php.appender.default.layout.param.bla = LoggerLayoutTTCC
+ 
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config3.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config3.php?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config3.php (added)
+++ logging/log4php/trunk/src/test/php/configurators/config3.php Sun Oct 16 07:12:49 2011
@@ -0,0 +1,5 @@
+<?php
+
+// Empty config
+
+?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config3.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config3.xml?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config3.xml (added)
+++ logging/log4php/trunk/src/test/php/configurators/config3.xml Sun Oct 16 07:12:49 2011
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration xmlns="http://logging.apache.org/log4php" threshold="debug">
+
+    <appender name="default" class="LoggerAppenderEcho">
+        <layout class="LoggerLayoutSimple"/>
+    </appender>
+    
+    <!-- Duplicate logger -->
+    <logger name="foo">
+        <level value="info" />
+        <appender_ref ref="default" />
+    </logger>
+    
+    <logger name="foo">
+        <level value="warn" />
+        <appender_ref ref="default" />
+    </logger>
+    
+    <root>
+        <level value="DEBUG" />
+        <appender_ref ref="default" />
+    </root>
+</configuration>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config4.ini
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config4.ini?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config4.ini (added)
+++ logging/log4php/trunk/src/test/php/configurators/config4.ini Sun Oct 16 07:12:49 2011
@@ -0,0 +1,7 @@
+log4php.rootLogger = DEBUG, default
+
+log4php.appender.default = LoggerAppenderEcho
+
+# invalid appender line should trigger warning
+log4php.appender.default.not-layout.param = LoggerLayoutTTCC
+ 
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config4.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config4.php?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config4.php (added)
+++ logging/log4php/trunk/src/test/php/configurators/config4.php Sun Oct 16 07:12:49 2011
@@ -0,0 +1,6 @@
+<?php
+
+// Not an array
+return new Exception();
+
+?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/php/configurators/config4.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/config4.xml?rev=1184770&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/config4.xml (added)
+++ logging/log4php/trunk/src/test/php/configurators/config4.xml Sun Oct 16 07:12:49 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration xmlns="http://logging.apache.org/log4php" threshold="debug">
+
+    <appender name="default" class="LoggerAppenderEcho">
+        <layout class="LoggerLayoutSimple"/>
+    </appender>
+    
+    <!-- Duplicate logger -->
+    <logger name="foo">
+        <level value="info" />
+        <appender_ref ref="default" />
+    </logger>
+    
+    <logger name="foo">
+        <level value="warn" />
+        <appender_ref ref="default" />
+    </logger>
+    
+    <root>
+        <level value="DEBUG" />
+        <appender_ref ref="default" />
+    </root>
+
+    <!-- Invalid XML file for testing -->
\ No newline at end of file

Modified: logging/log4php/trunk/src/test/php/filters/LoggerFilterDenyAllTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/filters/LoggerFilterDenyAllTest.php?rev=1184770&r1=1184769&r2=1184770&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/filters/LoggerFilterDenyAllTest.php (original)
+++ logging/log4php/trunk/src/test/php/filters/LoggerFilterDenyAllTest.php Sun Oct 16 07:12:49
2011
@@ -31,17 +31,41 @@ class LoggerFilterDenyAllTest extends PH
 	public function testDecide() {
 		$filter = new LoggerFilterDenyAll();
 		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
+		$events = array(
+			LoggerTestHelper::getTraceEvent(),
+			LoggerTestHelper::getDebugEvent(),
+			LoggerTestHelper::getInfoEvent(),
+			LoggerTestHelper::getWarnEvent(),
+			LoggerTestHelper::getErrorEvent(),
+			LoggerTestHelper::getFatalEvent(),
+		);
 		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::DENY);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::DENY);
-		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::DENY);
+		foreach($events as $event) {
+			$actual = $filter->decide($event);
+			self::assertEquals(LoggerFilter::DENY, $actual);
+		}
+    }
+    
+    public function testConfiguration() {
+    	$config = LoggerConfigurator::getDefaultConfiguration();
+    	$config['appenders']['default']['filters'] = array(
+    		array(
+    			'class' => 'LoggerFilterDenyAll'
+    		)
+    	);
+    	
+    	Logger::configure($config);
+    	$logger = Logger::getRootLogger();
+    	
+    	ob_start();
+    	$logger->trace('Test');
+    	$logger->debug('Test');
+    	$logger->info('Test');
+    	$logger->warn('Test');
+    	$logger->error('Test');
+    	$logger->fatal('Test');
+    	$actual = ob_get_clean();
+    	
+    	$this->assertEmpty($actual);
     }
 }

Modified: logging/log4php/trunk/src/test/php/filters/LoggerFilterLevelMatchTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/filters/LoggerFilterLevelMatchTest.php?rev=1184770&r1=1184769&r2=1184770&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/filters/LoggerFilterLevelMatchTest.php (original)
+++ logging/log4php/trunk/src/test/php/filters/LoggerFilterLevelMatchTest.php Sun Oct 16 07:12:49
2011
@@ -27,99 +27,155 @@
  * @group filters
  */
 class LoggerFilterLevelMatchTest extends PHPUnit_Framework_TestCase {
-        
-	public function testDecideAcceptErrorLevel() {
-		$filter = new LoggerFilterLevelMatch();
-		$filter->setAcceptOnMatch(true);
-		$filter->setLevelToMatch(LoggerLevel::getLevelError());
-		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
-		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::ACCEPT);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-    }
-    
-    public function testDecideDenyErrorLevel() {
-		$filter = new LoggerFilterLevelMatch();
-		$filter->setAcceptOnMatch("false");
-		$filter->setLevelToMatch(LoggerLevel::getLevelError());
-		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
-		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::DENY);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-    }
-    
-    public function testDecideAcceptWarnLevel() {
+
+	/** 
+	 * Tests all possible combinations of event level and filter levelToMatch 
+	 * option, with acceptOnMatch set to TRUE. 
+	 */
+	public function testDecideAccept() {
 		$filter = new LoggerFilterLevelMatch();
 		$filter->setAcceptOnMatch("true");
-		$filter->setLevelToMatch(LoggerLevel::getLevelWarn());
 		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
-		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::ACCEPT);
-    }
-    
-    public function testDecideDenyWarnLevel() {
-		$filter = new LoggerFilterLevelMatch();
-		$filter->setAcceptOnMatch("false");
-		$filter->setLevelToMatch(LoggerLevel::getLevelWarn());
+		$levels = LoggerTestHelper::getAllLevels();
+		$events = LoggerTestHelper::getAllEvents();
 		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
-		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::DENY);
-    }
-    
-    public function testDecideDenyDebugLevel() {
+		foreach($levels as $level) {
+			$filter->setLevelToMatch($level);
+			
+			foreach($events as $event) {
+				// Expecting given level to be accepted, neutral for others
+				$expected = ($event->getLevel() == $level) ? LoggerFilter::ACCEPT : LoggerFilter::NEUTRAL;
+				$actual = $filter->decide($event);
+					
+				// Get string represenations for logging
+				$sExpected = LoggerTestHelper::decisionToString($expected);
+				$sActual = LoggerTestHelper::decisionToString($actual);
+				
+				$this->assertSame($expected, $actual, "Failed asserting filter decision for event
level <$level>. Expected <$sExpected>, found <$sActual>.");
+			}
+		}
+	}
+	
+	/**
+	 * Tests all possible combinations of event level and filter levelToMatch
+	 * option, with acceptOnMatch set to TRUE.
+	 */
+	public function testDecideDeny() {
 		$filter = new LoggerFilterLevelMatch();
 		$filter->setAcceptOnMatch("false");
-		$filter->setLevelToMatch(LoggerLevel::getLevelDebug());
-		
-		$eventError = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(),
"testmessage");
-		$eventDebug = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelDebug(),
"testmessage");
-		$eventWarn = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelWarn(),
"testmessage");
-		
-		$result = $filter->decide($eventError);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-		
-		$result = $filter->decide($eventDebug);
-		self::assertEquals($result, LoggerFilter::DENY);
+	
+		$levels = LoggerTestHelper::getAllLevels();
+		$events = LoggerTestHelper::getAllEvents();
+	
+		foreach($levels as $level) {
+			$filter->setLevelToMatch($level);
+				
+			foreach($events as $event) {
+				// Expecting given level to be denied, neutral for others
+				$expected = ($event->getLevel() == $level) ? LoggerFilter::DENY : LoggerFilter::NEUTRAL;
+				$actual = $filter->decide($event);
+					
+				// Get string represenations for logging
+				$sExpected = LoggerTestHelper::decisionToString($expected);
+				$sActual = LoggerTestHelper::decisionToString($actual);
+	
+				$this->assertSame($expected, $actual, "Failed asserting filter decision for event
level <$level>. Expected <$sExpected>, found <$sActual>.");
+			}
+		}
+	}
+	
+	/** Test that filter always decides NEUTRAL when levelToMatch is not set. */
+	public function testDecideNull() {
+		$filter = new LoggerFilterLevelMatch();
+		$events = LoggerTestHelper::getAllEvents();
 		
-		$result = $filter->decide($eventWarn);
-		self::assertEquals($result, LoggerFilter::NEUTRAL);
-    }
+		foreach($events as $event) {
+			$expected = LoggerFilter::NEUTRAL;
+			$actual = $filter->decide($event);
+				
+			// Get string represenations for logging
+			$sExpected = LoggerTestHelper::decisionToString($expected);
+			$sActual = LoggerTestHelper::decisionToString($actual);
+			$level = $event->getLevel();
+			
+			$this->assertSame($expected, $actual, "Failed asserting filter decision for event level
<$level>. Expected <$sExpected>, found <$sActual>.");
+		}
+	}
+	
+	/** Test logger configuration. */
+	public function testAcceptConfig() {
+		$config = LoggerTestHelper::getEchoConfig();
+		
+		// Add filters to default appender
+		$config['appenders']['default']['filters'] = array(
+			
+			// Accepts only INFO events
+			array(
+				'class' => 'LoggerFilterLevelMatch',
+				'params' => array(
+					'levelToMatch' => 'info',
+					'acceptOnMatch' => true
+				)
+			),
+			
+			// Denies all events not accepted by first filter
+			array(
+				'class' => 'LoggerFilterDenyAll',
+			)
+		);
+		 
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+		 
+		ob_start();
+		$logger->trace('Test');
+		$logger->debug('Test');
+		$logger->info('Test');
+		$logger->warn('Test');
+		$logger->error('Test');
+		$logger->fatal('Test');
+		
+		$actual = ob_get_clean();
+
+		
+		$expected = "INFO - Test" . PHP_EOL;
+	}
+	
+	public function testDenyConfig() {
+		$config = LoggerTestHelper::getEchoConfig();
+	
+		// Add filter which denies INFO events
+		$config['appenders']['default']['filters'] = array(
+			array(
+				'class' => 'LoggerFilterLevelMatch',
+				'params' => array(
+					'levelToMatch' => 'info',
+					'acceptOnMatch' => false
+				)
+			)
+		);
+			
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+			
+		ob_start();
+		$logger->trace('Test');
+		$logger->debug('Test');
+		$logger->info('Test');
+		$logger->warn('Test');
+		$logger->error('Test');
+		$logger->fatal('Test');
+	
+		$actual = ob_get_clean();
+		
+		// Should log all except info
+		$expected = 
+			"TRACE - Test" . PHP_EOL . 
+			"DEBUG - Test" . PHP_EOL . 
+			"WARN - Test"  . PHP_EOL . 
+			"ERROR - Test" . PHP_EOL . 
+			"FATAL - Test" . PHP_EOL;	
+	
+		$this->assertSame($expected, $actual);
+	}
 }

Modified: logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php?rev=1184770&r1=1184769&r2=1184770&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php (original)
+++ logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php Sun Oct 16
07:12:49 2011
@@ -23,6 +23,8 @@
  * @link       http://logging.apache.org/log4php
  */
 
+require dirname(__FILE__) . '/../LoggerTestHelper.php';
+
 /**
  * @group filters
  */

Modified: logging/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php?rev=1184770&r1=1184769&r2=1184770&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php (original)
+++ logging/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php Sun Oct 16 07:12:49
2011
@@ -46,7 +46,6 @@ class LoggerRendererMapTest extends PHPU
 	public function testFindAndRender() {
 		$fruit = new Fruit3();
 		Logger::configure(dirname(__FILE__).'/test4.properties');
-		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 		
 		$map = $hierarchy->getRendererMap();
@@ -57,7 +56,6 @@ class LoggerRendererMapTest extends PHPU
 	public function testFindAndRenderDescendants() {
 		$fruit = new Fruit3Descendant();
 		Logger::configure(dirname(__FILE__).'/test4.properties');
-		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 
 		$map = $hierarchy->getRendererMap();
@@ -68,7 +66,6 @@ class LoggerRendererMapTest extends PHPU
 	public function testGetByObject() {
 		$fruit = new Fruit3();
 		Logger::configure(dirname(__FILE__).'/test4.properties');
-		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 		
 		$map = $hierarchy->getRendererMap();
@@ -78,7 +75,6 @@ class LoggerRendererMapTest extends PHPU
         
 	public function testGetByClassName() {
 		Logger::configure(dirname(__FILE__).'/test4.properties');
-		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 		
 		$map = $hierarchy->getRendererMap();
@@ -89,14 +85,14 @@ class LoggerRendererMapTest extends PHPU
 	public function testUsage() {
 	    Logger::resetConfiguration();
         Logger::configure(dirname(__FILE__).'/test4.properties');
-        Logger::initialize();
         $logger = Logger::getRootLogger();
  
         ob_start();
-        $logger->error(new Fruit3());
-        $v = ob_get_contents();
+        $logger->warn(new Fruit3());
+        $actual = ob_get_contents();
         ob_end_clean();
 
-        self::assertEquals("ERROR - test1,test2,test3" . PHP_EOL, $v);
+        $expected = "WARN - test1,test2,test3" . PHP_EOL;
+        self::assertEquals($expected, $actual);
 	}
 }

Modified: logging/log4php/trunk/src/test/php/renderers/test4.properties
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/renderers/test4.properties?rev=1184770&r1=1184769&r2=1184770&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/renderers/test4.properties (original)
+++ logging/log4php/trunk/src/test/php/renderers/test4.properties Sun Oct 16 07:12:49 2011
@@ -19,9 +19,9 @@ log4php.appender.default = LoggerAppende
 log4php.appender.default.layout = LoggerLayoutSimple
 log4php.appender.default.threshold = WARN
 
-log4php.appender.blub2 = LoggerAppenderEcho
+log4php.appender.rendr2 = LoggerAppenderEcho
 log4php.appender.rendr2.layout = LoggerLayoutSimple
-log4php.appender.rendr2.threshold = INFO
+log4php.appender.rendr2.threshold = ERROR
 
 log4php.threshold = WARN
 log4php.rootLogger = WARN, default, rendr2



Mime
View raw message