Author: grobmeier
Date: Sun Aug  2 15:42:58 2009
New Revision: 800099

URL: http://svn.apache.org/viewvc?rev=800099&view=rev
Log:
more Logger tests

Added:
    incubator/log4php/trunk/src/test/php/LoggerTest.properties
Modified:
    incubator/log4php/trunk/src/main/php/Logger.php
    incubator/log4php/trunk/src/test/php/LoggerTest.php

Modified: incubator/log4php/trunk/src/main/php/Logger.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/Logger.php?rev=800099&r1=800098&r2=800099&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/Logger.php (original)
+++ incubator/log4php/trunk/src/main/php/Logger.php Sun Aug  2 15:42:58 2009
@@ -333,7 +333,17 @@
        }
        
        /**
-        * Destroy loggers object tree.
+        * Clears all logger definitions
+        * 
+        * @static
+        * @return boolean 
+        */
+       public static function clear() {
+               return LoggerHierarchy::singleton()->clear();    
+       }
+       
+       /**
+        * Destroy configurations for logger definitions
         * 
         * @static
         * @return boolean 

Modified: incubator/log4php/trunk/src/test/php/LoggerTest.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/LoggerTest.php?rev=800099&r1=800098&r2=800099&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/LoggerTest.php (original)
+++ incubator/log4php/trunk/src/test/php/LoggerTest.php Sun Aug  2 15:42:58 2009
@@ -24,17 +24,21 @@
 
 class LoggerTest extends PHPUnit_Framework_TestCase {
        
-       public function testGetCurrentLoggers() {
-               //var_dump(Logger::getCurrentLoggers());
-               self::markTestIncomplete();
+       protected function setUp() {
+               Logger::clear();
+               Logger::resetConfiguration();
+       }
+       
+       protected function tearDown() {
+               Logger::clear();
+               Logger::resetConfiguration();
        }
        
        public function testLoggerExist() {
-//             $l = Logger::getRootLogger();
-//             self::assertEquals($l->getName(), 'root');
-//             $l->debug('test');
-//             self::assertTrue(Logger::exists('root'));
-               self::markTestIncomplete();
+               $l = Logger::getLogger('test');
+               self::assertEquals($l->getName(), 'test');
+               $l->debug('test');
+               self::assertTrue(Logger::exists('test'));
        }
        
        public function testCanGetRootLogger() {
@@ -46,6 +50,40 @@
        public function testCanGetASpecificLogger() {
                $l = Logger::getLogger('test');
                self::assertEquals($l->getName(), 'test');
-
+       }
+       
+       public function testCanLogToAllLevels() {
+               LoggerConfiguratorIni::configure('LoggerTest.properties');
+               
+               $logger = Logger::getLogger('mylogger');
+               ob_start();
+               $logger->info('this is an info');
+               $logger->warn('this is a warning');
+               $logger->error('this is an error');
+               $logger->debug('this is a debug message');
+               $logger->fatal('this is a fatal message');
+               
+               $v = ob_get_contents();
+               ob_end_clean();
+               
+               $e = 'INFO - this is an info'.PHP_EOL;
+               $e .= 'WARN - this is a warning'.PHP_EOL;
+               $e .= 'ERROR - this is an error'.PHP_EOL;
+               $e .= 'DEBUG - this is a debug message'.PHP_EOL;
+               $e .= 'FATAL - this is a fatal message'.PHP_EOL;
+               
+               self::assertEquals($v, $e);
+       }
+       
+       public function testGetCurrentLoggers() {
+               Logger::clear();
+               Logger::resetConfiguration();
+               
+               self::assertEquals(0, count(Logger::getCurrentLoggers()));
+               
+               LoggerConfiguratorIni::configure('LoggerTest.properties');
+               self::assertEquals(1, count(Logger::getCurrentLoggers()));
+               $list = Logger::getCurrentLoggers();
+               self::assertEquals('mylogger', $list[0]->getName());
        }
 }

Added: incubator/log4php/trunk/src/test/php/LoggerTest.properties
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/LoggerTest.properties?rev=800099&view=auto
==============================================================================
--- incubator/log4php/trunk/src/test/php/LoggerTest.properties (added)
+++ incubator/log4php/trunk/src/test/php/LoggerTest.properties Sun Aug  2 
15:42:58 2009
@@ -0,0 +1,21 @@
+; 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.
+;
+log4php.appender.loggertestdefault = LoggerAppenderEcho
+log4php.appender.loggertestdefault.layout = LoggerLayoutSimple
+
+log4php.additivity.mylogger= "false"
+log4php.logger.mylogger = DEBUG, loggertestdefault
+log4php.rootLogger = WARN, loggertestdefault


Reply via email to