LOG4PHP-102: Added patch from Ivan Habunek: LoggerLayoutPattern fails tests
authorChristian Grobmeier <grobmeier@apache.org>
Mon, 22 Mar 2010 06:35:24 +0000 (06:35 +0000)
committerChristian Grobmeier <grobmeier@apache.org>
Mon, 22 Mar 2010 06:35:24 +0000 (06:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/incubator/log4php/trunk@925973 13f79535-47bb-0310-9956-ffa450edef68

src/changes/changes.xml
src/main/php/helpers/LoggerPatternConverter.php
src/test/php/layouts/LoggerLayoutPatternTest.php

index c90ac7c..d5f53ec 100644 (file)
@@ -24,7 +24,8 @@
   </properties>
   <body>
        <release version="2.1" description="Stabilizing">
-               <action type="update" issue="LOG4PHP-103" by="Moritz Schmidt">Exception when using more than one LoggerAppenderFile</action>
+               <action type="fix" issue="LOG4PHP-103" by="Moritz Schmidt">Exception when using more than one LoggerAppenderFile</action>
+               <action type="fix" issue="LOG4PHP-102" by="Ivan Habunek">LoggerLayoutPattern fails tests</action>
                <action type="update" issue="LOG4PHP-100" by="Moritz Schmidt">Directly assign an array on Logger PHP configuration</action>
                <action type="fix" issue="LOG4PHP-91">LoginOptionConverter.php (used wrong constant name)</action>
                <action type="update" issue="LOG4PHP-95" by="Ivan Habunek, Christian Grobmeier">Add trace level to Log4PHP</action>
index 8b233e8..e694148 100644 (file)
  * @package log4php
  */
 
-/**
- * Array for fast space padding
- * Used by {@link LoggerPatternConverter::spacePad()}. 
- * 
- * @package log4php
- * @subpackage helpers
- */
-$GLOBALS['log4php.LoggerPatternConverter.spaces'] = array(
-       " ", // 1 space
-       "  ", // 2 spaces
-       "    ", // 4 spaces
-       "        ", // 8 spaces
-       "                ", // 16 spaces
-       "                                " ); // 32 spaces
-
 
 /**
  * LoggerPatternConverter is an abstract class that provides the formatting 
@@ -49,7 +34,19 @@ $GLOBALS['log4php.LoggerPatternConverter.spaces'] = array(
  * @since 0.3
  */
 class LoggerPatternConverter {
-
+       
+       /**
+        * Array for fast space padding
+        * Used by {@link LoggerPatternConverter::spacePad()}.  
+        */
+       private $spaces = array(
+               " ", // 1 space
+               "  ", // 2 spaces
+               "    ", // 4 spaces
+               "        ", // 8 spaces
+               "                ", // 16 spaces
+               "                                "); // 32 spaces 
+        
        /**
         * @var LoggerPatternConverter next converter in converter chain
         */
@@ -123,13 +120,13 @@ class LoggerPatternConverter {
         */
        public function spacePad(&$sbuf, $length) {
                while($length >= 32) {
-                 $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][5];
+                 $sbuf .= $this->spaces[5];
                  $length -= 32;
                }
                
                for($i = 4; $i >= 0; $i--) {    
                        if(($length & (1<<$i)) != 0) {
-                               $sbuf .= $GLOBALS['log4php.LoggerPatternConverter.spaces'][$i];
+                               $sbuf .= $this->spaces[$i];
                        }
                }
 
index 782e31f..37168ea 100644 (file)
@@ -37,25 +37,13 @@ class LoggerLayoutPatternTest extends PHPUnit_Framework_TestCase {
                self::assertEquals($v, $e);
     }
     
-    public function XtestWarnLayout() {
-       /*
-Comment in when this has been fixed:
-
-1) testWarnLayout(LoggerLayoutPatternTest)
-Undefined index:  log4php.LoggerPatternConverter.spaces
-/Users/cgrobmeier/Documents/Development/workspace/log4php-trunk/src/main/php/helpers/LoggerPatternConverter.php:131
-/Users/cgrobmeier/Documents/Development/workspace/log4php-trunk/src/main/php/helpers/LoggerPatternConverter.php:104
-/Users/cgrobmeier/Documents/Development/workspace/log4php-trunk/src/main/php/layouts/LoggerPatternLayout.php:216
-/Users/cgrobmeier/Documents/Development/workspace/log4php-trunk/src/test/php/layouts/LoggerLayoutPatternTest.php:45
-
-        * 
-        */
+    public function testWarnLayout() {
                $event = new LoggerLoggingEvent("LoggerLayoutXml", new Logger("TEST"), LoggerLevel::getLevelWarn(), "testmessage");
 
                $layout = new LoggerLayoutPattern();
                $layout->setConversionPattern("%-5p %c %X{username}: %m in %F at %L%n");
                $v = $layout->format($event);
-               $e = 'WARN TEST : testmessage in NA at NA'.PHP_EOL;
+               $e = 'WARN  TEST : testmessage in NA at NA'.PHP_EOL;
                
                self::assertEquals($v, $e);
     }