logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1237446 - in /logging/log4php/trunk/src: main/php/helpers/LoggerOptionConverter.php test/php/configurators/LoggerConfigurationAdapterINITest.php test/resources/configs/adapters/ini/values.ini
Date Sun, 29 Jan 2012 20:10:11 GMT
Author: ihabunek
Date: Sun Jan 29 20:10:11 2012
New Revision: 1237446

URL: http://svn.apache.org/viewvc?rev=1237446&view=rev
Log:
LOG4PHP-167: Fixed converting of boolean values read from ini file without the INI_SCANNER_RAW
option. Added more tests.

Added:
    logging/log4php/trunk/src/test/resources/configs/adapters/ini/values.ini
Modified:
    logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php
    logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterINITest.php

Modified: logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php?rev=1237446&r1=1237445&r2=1237446&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php (original)
+++ logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php Sun Jan 29 20:10:11
2012
@@ -36,8 +36,14 @@ class LoggerOptionConverter {
 	/** String values which are converted to boolean TRUE. */
 	private static $trueValues = array('1', 'true', 'yes', 'on');
 	
-	/** String values which are converted to boolean FALSE. */
-	private static $falseValues = array('0', 'false', 'no', 'off');
+	/** 
+	 * String values which are converted to boolean FALSE.
+	 * 
+	 * Note that an empty string must convert to false, because 
+	 * parse_ini_file() which is used for parsing configuration 
+	 * converts the value _false_ to an empty string.
+	 */
+	private static $falseValues = array('0', 'false', 'no', 'off', '');
 	
 	/**
 	 * Read a predefined var.

Modified: logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterINITest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterINITest.php?rev=1237446&r1=1237445&r2=1237446&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterINITest.php
(original)
+++ logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterINITest.php
Sun Jan 29 20:10:11 2012
@@ -130,6 +130,39 @@ class LoggerConfigurationAdapterINITest 
 		$adapter = new LoggerConfigurationAdapterINI();
 		$adapter->convert($url);
 	}
+
+	/**
+	 * Check that various boolean equivalents from ini file convert properly 
+	 * to boolean. 
+	 */
+	public function testBooleanValues() {
+		$values = parse_ini_file(PHPUNIT_CONFIG_DIR . '/adapters/ini/values.ini');
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_true']);
+		self::assertTrue($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_yes']);
+		self::assertTrue($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_false']);
+		self::assertFalse($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_no']);
+		self::assertFalse($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['quoted_true']);
+		self::assertTrue($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['quoted_false']);
+		self::assertFalse($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_one']);
+		self::assertTrue($actual);
+		
+		$actual = LoggerOptionConverter::toBooleanEx($values['unquoted_zero']);
+		self::assertFalse($actual);
+	}
+	
 }
 
 ?>
\ No newline at end of file

Added: logging/log4php/trunk/src/test/resources/configs/adapters/ini/values.ini
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/resources/configs/adapters/ini/values.ini?rev=1237446&view=auto
==============================================================================
--- logging/log4php/trunk/src/test/resources/configs/adapters/ini/values.ini (added)
+++ logging/log4php/trunk/src/test/resources/configs/adapters/ini/values.ini Sun Jan 29 20:10:11
2012
@@ -0,0 +1,8 @@
+unquoted_true = true
+unquoted_false = false
+unquoted_yes = true
+unquoted_no = false
+quoted_true = "true"
+quoted_false = "false"
+unquoted_one = 1
+unquoted_zero = 0
\ No newline at end of file



Mime
View raw message