logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject [01/43] LOG4PHP-121: Reorganized classes into namespaces
Date Thu, 28 Nov 2013 16:03:31 GMT
Updated Branches:
  refs/heads/v3 [created] 75ec90ff5


http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/LoggerTest.php
----------------------------------------------------------------------
diff --git a/tests/src/LoggerTest.php b/tests/src/LoggerTest.php
new file mode 100644
index 0000000..a511aa4
--- /dev/null
+++ b/tests/src/LoggerTest.php
@@ -0,0 +1,225 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\Logger;
+
+/**
+ * @group main
+ */
+class LoggerTest extends \PHPUnit_Framework_TestCase {
+
+	private $testConfig1 = array (
+		'rootLogger' =>	array (
+			'level' => 'ERROR',
+			'appenders' => array (
+				'default',
+			),
+		),
+		'appenders' => array (
+			'default' => array (
+				'class' => 'EchoAppender',
+			),
+		),
+		'loggers' => array (
+			'mylogger' => array (
+				'additivity' => 'false',
+				'level' => 'DEBUG',
+				'appenders' => array (
+					'default',
+				),
+			),
+		),
+	);
+
+	// For testing additivity
+	private $testConfig2 = array (
+		'appenders' => array (
+			'default' => array (
+				'class' => 'EchoAppender',
+			),
+		),
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'loggers' => array (
+			'foo' => array (
+				'appenders' => array (
+					'default',
+				),
+			),
+			'foo.bar' => array (
+				'appenders' => array (
+					'default',
+				),
+			),
+			'foo.bar.baz' => array (
+				'appenders' => array (
+					'default',
+				),
+			),
+		),
+	);
+
+	// For testing additivity
+	private $testConfig3 = array (
+		'appenders' => array (
+			'default' => array (
+				'class' => 'EchoAppender',
+			),
+		),
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'loggers' => array (
+			'foo' => array (
+				'appenders' => array (
+					'default',
+				),
+			),
+			'foo.bar' => array (
+				'appenders' => array (
+					'default',
+				),
+			),
+			'foo.bar.baz' => array (
+				'level' => 'ERROR',
+				'appenders' => array (
+					'default',
+				),
+			),
+		),
+	);
+
+	protected function setUp() {
+		Logger::clear();
+		Logger::resetConfiguration();
+	}
+
+	protected function tearDown() {
+		Logger::clear();
+		Logger::resetConfiguration();
+	}
+
+	public function testLoggerExist() {
+		$l = Logger::getLogger('test');
+		self::assertEquals($l->getName(), 'test');
+		self::assertTrue(Logger::exists('test'));
+	}
+
+	public function testCanGetRootLogger() {
+		$l = Logger::getRootLogger();
+		self::assertEquals($l->getName(), 'root');
+	}
+
+	public function testCanGetASpecificLogger() {
+		$l = Logger::getLogger('test');
+		self::assertEquals($l->getName(), 'test');
+	}
+
+	public function testCanLogToAllLevels() {
+		Logger::configure($this->testConfig1);
+
+		$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 testIsEnabledFor() {
+		Logger::configure($this->testConfig1);
+
+		$logger = Logger::getLogger('mylogger');
+
+		self::assertFalse($logger->isTraceEnabled());
+		self::assertTrue($logger->isDebugEnabled());
+		self::assertTrue($logger->isInfoEnabled());
+		self::assertTrue($logger->isWarnEnabled());
+		self::assertTrue($logger->isErrorEnabled());
+		self::assertTrue($logger->isFatalEnabled());
+
+		$logger = Logger::getRootLogger();
+
+		self::assertFalse($logger->isTraceEnabled());
+		self::assertFalse($logger->isDebugEnabled());
+		self::assertFalse($logger->isInfoEnabled());
+		self::assertFalse($logger->isWarnEnabled());
+		self::assertTrue($logger->isErrorEnabled());
+		self::assertTrue($logger->isFatalEnabled());
+	}
+
+	public function testGetCurrentLoggers() {
+		Logger::clear();
+		Logger::resetConfiguration();
+
+		self::assertEquals(0, count(Logger::getCurrentLoggers()));
+
+		Logger::configure($this->testConfig1);
+		self::assertEquals(1, count(Logger::getCurrentLoggers()));
+		$list = Logger::getCurrentLoggers();
+		self::assertEquals('mylogger', $list[0]->getName());
+	}
+
+	public function testAdditivity() {
+		Logger::configure($this->testConfig2);
+
+		$logger = Logger::getLogger('foo.bar.baz');
+		ob_start();
+		$logger->info('test');
+		$actual = ob_get_contents();
+		ob_end_clean();
+
+		// The message should get logged 4 times: once by every logger in the
+		//  hierarchy (including root)
+		$expected = str_repeat('INFO - test' . PHP_EOL, 4);
+		self::assertSame($expected, $actual);
+	}
+
+	public function testAdditivity2() {
+		Logger::configure($this->testConfig3);
+
+		$logger = Logger::getLogger('foo.bar.baz');
+		ob_start();
+		$logger->info('test');
+		$actual = ob_get_contents();
+		ob_end_clean();
+
+		// The message should get logged 3 times: once by every logger in the
+		//  hierarchy, except foo.bar.baz which is set to level ERROR
+		$expected = str_repeat('INFO - test' . PHP_EOL, 3);
+		self::assertSame($expected, $actual);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/LoggingEventTest.php
----------------------------------------------------------------------
diff --git a/tests/src/LoggingEventTest.php b/tests/src/LoggingEventTest.php
new file mode 100644
index 0000000..f07e7c3
--- /dev/null
+++ b/tests/src/LoggingEventTest.php
@@ -0,0 +1,139 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\Appenders\NullAppender;
+use Apache\Log4php\Layouts\AbstractLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+class LoggingEventTestCaseAppender extends NullAppender {
+
+	protected $requiresLayout = true;
+
+	public function append(LoggingEvent $event) {
+		$this->layout->format($event);
+	}
+}
+
+class LoggingEventTestCaseLayout extends AbstractLayout {
+
+	public function activateOptions() {
+		return;
+	}
+
+	public function format(LoggingEvent $event) {
+		LoggingEventTest::$locationInfo  = $event->getLocationInformation();
+        LoggingEventTest::$throwableInfo = $event->getThrowableInformation();
+	}
+}
+
+/**
+ * @group main
+ */
+class LoggingEventTest extends \PHPUnit_Framework_TestCase {
+
+	public static $locationInfo;
+    public static $throwableInfo;
+
+	public function testConstructWithLoggerName() {
+		$l = Level::getLevelDebug();
+		$e = new LoggingEvent('fqcn', 'TestLogger', $l, 'test');
+		self::assertEquals($e->getLoggerName(), 'TestLogger');
+	}
+
+	public function testConstructWithTimestamp() {
+		$l = Level::getLevelDebug();
+		$timestamp = microtime(true);
+		$e = new LoggingEvent('fqcn', 'TestLogger', $l, 'test', $timestamp);
+		self::assertEquals($e->getTimeStamp(), $timestamp);
+ 	}
+
+	public function testGetStartTime() {
+		$time = LoggingEvent::getStartTime();
+		self::assertInternalType('float', $time);
+		$time2 = LoggingEvent::getStartTime();
+		self::assertEquals($time, $time2);
+	}
+
+	public function testGetLocationInformation() {
+		$hierarchy = Logger::getHierarchy();
+		$root = $hierarchy->getRootLogger();
+
+		$a = new LoggingEventTestCaseAppender('A1');
+		$a->setLayout(new LoggingEventTestCaseLayout());
+		$root->addAppender($a);
+
+		$logger = $hierarchy->getLogger('test');
+
+		$line = __LINE__; $logger->debug('test');
+		$hierarchy->shutdown();
+
+		$li = self::$locationInfo;
+
+		self::assertEquals(get_class($this), $li->getClassName());
+		self::assertEquals(__FILE__, $li->getFileName());
+		self::assertEquals($line, $li->getLineNumber());
+		self::assertEquals(__FUNCTION__, $li->getMethodName());
+	}
+
+	public function testGetThrowableInformation1() {
+		$hierarchy = Logger::getHierarchy();
+		$root = $hierarchy->getRootLogger();
+
+		$a = new LoggingEventTestCaseAppender('A1');
+		$a->setLayout( new LoggingEventTestCaseLayout() );
+		$root->addAppender($a);
+
+		$logger = $hierarchy->getLogger('test');
+		$logger->debug('test');
+		$hierarchy->shutdown();
+
+		$ti = self::$throwableInfo;
+
+		self::assertEquals($ti, null);
+	}
+
+	public function testGetThrowableInformation2() {
+		$hierarchy = Logger::getHierarchy();
+		$root = $hierarchy->getRootLogger();
+
+		$a = new LoggingEventTestCaseAppender('A1');
+		$a->setLayout( new LoggingEventTestCaseLayout() );
+		$root->addAppender($a);
+
+		$ex	= new \Exception('Message1');
+		$logger = $hierarchy->getLogger('test');
+		$logger->debug('test', $ex);
+		$hierarchy->shutdown();
+
+		$ti = self::$throwableInfo;
+
+		self::assertInstanceOf("Apache\\Log4php\\ThrowableInformation", $ti);
+
+		$result	= $ti->getStringRepresentation();
+		self::assertInternalType('array', $result);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/MDCTest.php
----------------------------------------------------------------------
diff --git a/tests/src/MDCTest.php b/tests/src/MDCTest.php
new file mode 100644
index 0000000..0d33383
--- /dev/null
+++ b/tests/src/MDCTest.php
@@ -0,0 +1,119 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\MDC;
+use Apache\Log4php\Layouts\PatternLayout;
+
+/**
+ * @group main
+ */
+class MDCTest extends \PHPUnit_Framework_TestCase {
+
+	/** A pattern with 1 key. */
+	private $pattern1 = "%-5p %c: %X{key1} %m";
+
+	/** A pattern with 2 keys. */
+	private $pattern2 = "%-5p %c: %X{key1} %X{key2} %m";
+
+	/** A pattern with 3 keys (one is numeric). */
+	private $pattern3 = "%-5p %c: %X{key1} %X{key2} %X{3} %m";
+
+	/** A pattern with a non-existant key. */
+	private $pattern4 = "%-5p %c: %X{key_does_not_exist} %m";
+
+	/** A pattern without a key. */
+	private $pattern5 = "%-5p %c: %X %m";
+
+	protected function setUp() {
+		MDC::clear();
+	}
+
+	protected function tearDown() {
+		MDC::clear();
+	}
+
+	public function testPatterns() {
+
+		// Create some data to test with
+		MDC::put('key1', 'valueofkey1');
+		MDC::put('key2', 'valueofkey2');
+		MDC::put(3, 'valueofkey3');
+
+		$expected = array(
+			'key1' => 'valueofkey1',
+			'key2' => 'valueofkey2',
+			3 => 'valueofkey3',
+		);
+		$actual = MDC::getMap();
+
+		self::assertSame($expected, $actual);
+
+		$event = TestHelper::getInfoEvent("Test message");
+
+		// Pattern with 1 key
+		$actual = $this->formatEvent($event, $this->pattern1);
+		$expected = "INFO  test: valueofkey1 Test message";
+		self::assertEquals($expected, $actual);
+
+		// Pattern with 2 keys
+		$actual = $this->formatEvent($event, $this->pattern2);
+		$expected = "INFO  test: valueofkey1 valueofkey2 Test message";
+		self::assertEquals($expected, $actual);
+
+		// Pattern with 3 keys (one numeric)
+		$actual = $this->formatEvent($event, $this->pattern3);
+		$expected = "INFO  test: valueofkey1 valueofkey2 valueofkey3 Test message";
+		self::assertEquals($expected, $actual);
+
+		// Pattern with non-existant key
+		$actual = $this->formatEvent($event, $this->pattern4);
+		$expected = "INFO  test:  Test message";
+		self::assertEquals($expected, $actual);
+
+		// Pattern with an empty key
+    	$actual = $this->formatEvent($event, $this->pattern5);
+		$expected = "INFO  test: key1=valueofkey1, key2=valueofkey2, 3=valueofkey3 Test message";
+		self::assertEquals($expected, $actual);
+
+		// Test key removal
+		MDC::remove('key1');
+		$value = MDC::get('key1');
+		self::assertEquals('', $value);
+
+		// Pattern with 1 key, now removed
+		$actual = $this->formatEvent($event, $this->pattern1);
+		$expected = "INFO  test:  Test message";
+		self::assertEquals($expected, $actual);
+    }
+
+	private function formatEvent($event, $pattern) {
+		$layout = new PatternLayout();
+		$layout->setConversionPattern($pattern);
+		$layout->activateOptions();
+		return $layout->format($event);
+	}
+}
+
+?>

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/NDCTest.php
----------------------------------------------------------------------
diff --git a/tests/src/NDCTest.php b/tests/src/NDCTest.php
new file mode 100644
index 0000000..b65b822
--- /dev/null
+++ b/tests/src/NDCTest.php
@@ -0,0 +1,94 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\NDC;
+
+/**
+ * @group main
+ */
+class NDCTest extends \PHPUnit_Framework_TestCase {
+
+	public function testItemHandling()
+	{
+		// Test the empty stack
+		self::assertSame('', NDC::get());
+		self::assertSame('', NDC::peek());
+		self::assertSame(0, NDC::getDepth());
+		self::assertSame('', NDC::pop());
+
+		// Add some data to the stack
+		NDC::push('1');
+		NDC::push('2');
+		NDC::push('3');
+
+		self::assertSame('1 2 3', NDC::get());
+		self::assertSame('3', NDC::peek());
+		self::assertSame(3, NDC::getDepth());
+
+		// Remove last item
+		self::assertSame('3', NDC::pop());
+		self::assertSame('1 2', NDC::get());
+		self::assertSame('2', NDC::peek());
+		self::assertSame(2, NDC::getDepth());
+
+		// Remove all items
+		NDC::remove();
+
+		// Test the empty stack
+		self::assertSame('', NDC::get());
+		self::assertSame('', NDC::peek());
+		self::assertSame(0, NDC::getDepth());
+		self::assertSame('', NDC::pop());
+	}
+
+	public function testMaxDepth()
+	{
+		// Clear stack; add some testing data
+		NDC::clear();
+		NDC::push('1');
+		NDC::push('2');
+		NDC::push('3');
+		NDC::push('4');
+		NDC::push('5');
+		NDC::push('6');
+
+		self::assertSame('1 2 3 4 5 6', NDC::get());
+
+		// Edge case, should not change stack
+		NDC::setMaxDepth(6);
+		self::assertSame('1 2 3 4 5 6', NDC::get());
+		self::assertSame(6, NDC::getDepth());
+
+		NDC::setMaxDepth(3);
+		self::assertSame('1 2 3', NDC::get());
+		self::assertSame(3, NDC::getDepth());
+
+		NDC::setMaxDepth(0);
+		self::assertSame('', NDC::get());
+		self::assertSame(0, NDC::getDepth());
+	}
+}
+
+?>

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Pattern/PatternConverterTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Pattern/PatternConverterTest.php b/tests/src/Pattern/PatternConverterTest.php
new file mode 100644
index 0000000..e491dba
--- /dev/null
+++ b/tests/src/Pattern/PatternConverterTest.php
@@ -0,0 +1,415 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests\Pattern;
+
+use Apache\Log4php\Helpers\FormattingInfo;
+use Apache\Log4php\Logger;
+use Apache\Log4php\MDC;
+use Apache\Log4php\NDC;
+
+use Apache\Log4php\Pattern\ClassConverter;
+use Apache\Log4php\Pattern\CookieConverter;
+use Apache\Log4php\Pattern\DateConverter;
+use Apache\Log4php\Pattern\EnvironmentConverter;
+use Apache\Log4php\Pattern\FileConverter;
+use Apache\Log4php\Pattern\LevelConverter;
+use Apache\Log4php\Pattern\LineConverter;
+use Apache\Log4php\Pattern\LiteralConverter;
+use Apache\Log4php\Pattern\LocationConverter;
+use Apache\Log4php\Pattern\LoggerConverter;
+use Apache\Log4php\Pattern\MdcConverter;
+use Apache\Log4php\Pattern\MessageConverter;
+use Apache\Log4php\Pattern\MethodConverter;
+use Apache\Log4php\Pattern\NdcConverter;
+use Apache\Log4php\Pattern\NewLineConverter;
+use Apache\Log4php\Pattern\ProcessConverter;
+use Apache\Log4php\Pattern\RelativeConverter;
+use Apache\Log4php\Pattern\RequestConverter;
+use Apache\Log4php\Pattern\ServerConverter;
+use Apache\Log4php\Pattern\SessionConverter;
+use Apache\Log4php\Pattern\SessionIdConverter;
+use Apache\Log4php\Pattern\SuperglobalConverter;
+use Apache\Log4php\Pattern\ThrowableConverter;
+
+
+use Apache\Log4php\Tests\TestHelper;
+
+/** Converter referencing non-existant superglobal variable. */
+class InvalidSuperglobalConverter extends SuperglobalConverter {
+	protected $name = '_FOO';
+}
+
+/**
+ * @group pattern
+ */
+class PatternConverterTest extends \PHPUnit_Framework_TestCase {
+
+	/**
+	 * A logging event for testing.
+	 * @var LoggingEvent
+	 */
+	private $event;
+
+	/**
+	 * Fromatting info used with the logging event.
+	 * @var LoggerFormattingInfos
+	 */
+	private $info;
+
+	public function __construct() {
+		$this->event = TestHelper::getInfoEvent('foobar');
+		$this->info = new FormattingInfo();
+	}
+
+	public function testCookie() {
+		// Fake a couple of cookies
+		$_COOKIE['test1'] = 'value1';
+		$_COOKIE['test2'] = 'value2';
+
+		$converter = new CookieConverter($this->info, 'test1');
+		$actual = $converter->convert($this->event);
+		$expected = 'value1';
+		self::assertSame($expected, $actual);
+
+		$converter = new CookieConverter($this->info, 'test2');
+		$actual = $converter->convert($this->event);
+		$expected = 'value2';
+		self::assertSame($expected, $actual);
+
+		$converter = new CookieConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = "test1=value1, test2=value2";
+		self::assertSame($expected, $actual);
+	}
+
+	public function testDate() {
+		$converter = new DateConverter($this->info, 'c');
+		$actual = $converter->convert($this->event);
+		$expected = date('c', $this->event->getTimeStamp());
+		self::assertSame($expected, $actual);
+
+		// Format defaults to 'c'
+		$converter = new DateConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = date('c', $this->event->getTimeStamp());
+		self::assertSame($expected, $actual);
+
+		$converter = new DateConverter($this->info, '');
+		$actual = $converter->convert($this->event);
+		$expected = date('c', $this->event->getTimeStamp());
+		self::assertSame($expected, $actual);
+
+		// Test ABSOLUTE
+		$converter = new DateConverter($this->info, 'ABSOLUTE');
+		$actual = $converter->convert($this->event);
+		$expected = date('H:i:s', $this->event->getTimeStamp());
+		self::assertSame($expected, $actual);
+
+		// Test DATE
+		$converter = new DateConverter($this->info, 'DATE');
+		$actual = $converter->convert($this->event);
+		$expected = date('d M Y H:i:s.', $this->event->getTimeStamp());
+
+		$timestamp = $this->event->getTimeStamp();
+		$ms = floor(($timestamp - floor($timestamp)) * 1000);
+		$ms = str_pad($ms, 3, '0', STR_PAD_LEFT);
+
+		$expected .= $ms;
+
+		self::assertSame($expected, $actual);
+	}
+
+	public function testEnvironment() {
+		// Fake a couple of environment values
+		$_ENV['test1'] = 'value1';
+		$_ENV['test2'] = 'value2';
+
+		$converter = new EnvironmentConverter($this->info, 'test1');
+		$actual = $converter->convert($this->event);
+		$expected = 'value1';
+		self::assertSame($expected, $actual);
+
+		$converter = new EnvironmentConverter($this->info, 'test2');
+		$actual = $converter->convert($this->event);
+		$expected = 'value2';
+		self::assertSame($expected, $actual);
+	}
+
+	public function testLevel() {
+		$converter = new LevelConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = $this->event->getLevel()->toString();
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testLiteral() {
+		$converter = new LiteralConverter('foo bar baz');
+		$actual = $converter->convert($this->event);
+		$expected = 'foo bar baz';
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testLoggerWithoutOption() {
+		$event = TestHelper::getInfoEvent('foo', 'TestLoggerName');
+		$converter = new LoggerConverter($this->info);
+
+		$actual = $converter->convert($event);
+		$expected = 'TestLoggerName';
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testLoggerWithOption0() {
+		$event = TestHelper::getInfoEvent('foo', 'TestLoggerName');
+		$converter = new LoggerConverter($this->info, '0');
+
+		$actual = $converter->convert($event);
+		$expected = 'TestLoggerName';
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testLocation() {
+		$config = TestHelper::getEchoPatternConfig("%file:%line:%class:%method");
+		Logger::configure($config);
+
+		// Test by capturing output. Logging methods of a Logger object must
+		// be used for the location info to be formed correctly.
+		ob_start();
+		$log = Logger::getLogger('foo');
+		$log->info('foo'); $line = __LINE__; // Do NOT move this to next line.
+		$actual = ob_get_contents();
+		ob_end_clean();
+
+		$expected = implode(':', array(__FILE__, $line, __CLASS__, __FUNCTION__));
+		self::assertSame($expected, $actual);
+
+		Logger::resetConfiguration();
+	}
+
+	public function testLocation2() {
+		$config = TestHelper::getEchoPatternConfig("%location");
+		Logger::configure($config);
+
+		// Test by capturing output. Logging methods of a Logger object must
+		// be used for the location info to be formed correctly.
+		ob_start();
+		$log = Logger::getLogger('foo');
+		$log->info('foo'); $line = __LINE__; // Do NOT move this to next line.
+		$actual = ob_get_contents();
+		ob_end_clean();
+
+		$class = __CLASS__;
+		$func = __FUNCTION__;
+		$file = __FILE__;
+
+		$expected = "$class.$func($file:$line)";
+		self::assertSame($expected, $actual);
+
+		Logger::resetConfiguration();
+	}
+
+	public function testMessage() {
+		$expected = "This is a message.";
+		$event = TestHelper::getInfoEvent($expected);
+		$converter = new MessageConverter($this->info);
+		$actual = $converter->convert($event);
+		self::assertSame($expected, $actual);
+	}
+
+	public function testMDC() {
+		MDC::put('foo', 'bar');
+		MDC::put('bla', 'tra');
+
+		// Entire context
+		$converter = new MdcConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = 'foo=bar, bla=tra';
+		self::assertSame($expected, $actual);
+
+		// Just foo
+		$converter = new MdcConverter($this->info, 'foo');
+		$actual = $converter->convert($this->event);
+		$expected = 'bar';
+		self::assertSame($expected, $actual);
+
+		// Non existant key
+		$converter = new MdcConverter($this->info, 'doesnotexist');
+		$actual = $converter->convert($this->event);
+		$expected = '';
+		self::assertSame($expected, $actual);
+
+		MDC::clear();
+	}
+
+	public function testNDC() {
+		NDC::push('foo');
+		NDC::push('bar');
+		NDC::push('baz');
+
+		$converter = new NdcConverter($this->info);
+		$expected = 'foo bar baz';
+		$actual = $converter->convert($this->event);
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testNewline() {
+		$converter = new NewLineConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = PHP_EOL;
+		self::assertSame($expected, $actual);
+	}
+
+	public function testProcess() {
+		$converter = new ProcessConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = getmypid();
+		self::assertSame($expected, $actual);
+	}
+
+	public function testRelative() {
+		$converter = new RelativeConverter($this->info);
+		$expected = number_format($this->event->getTimeStamp() - $this->event->getStartTime(), 4);
+		$actual = $converter->convert($this->event);
+		self::assertSame($expected, $actual);
+	}
+
+	public function testRequest() {
+		// Fake a couple of request values
+		$_REQUEST['test1'] = 'value1';
+		$_REQUEST['test2'] = 'value2';
+
+		// Entire request
+		$converter = new RequestConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = 'test1=value1, test2=value2';
+		self::assertSame($expected, $actual);
+
+		// Just test2
+		$converter = new RequestConverter($this->info, 'test2');
+		$actual = $converter->convert($this->event);
+		$expected = 'value2';
+		self::assertSame($expected, $actual);
+	}
+
+	public function testServer() {
+		// Fake a server value
+		$_SERVER['test1'] = 'value1';
+
+		$converter = new ServerConverter($this->info, 'test1');
+		$actual = $converter->convert($this->event);
+		$expected = 'value1';
+		self::assertSame($expected, $actual);
+	}
+
+	public function testSession() {
+		// Fake a session value
+		$_SESSION['test1'] = 'value1';
+
+		$converter = new SessionConverter($this->info, 'test1');
+		$actual = $converter->convert($this->event);
+		$expected = 'value1';
+		self::assertSame($expected, $actual);
+	}
+
+	public function testSessionID() {
+		$converter = new SessionIdConverter($this->info);
+		$actual = $converter->convert($this->event);
+		$expected = session_id();
+		self::assertSame($expected, $actual);
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage log4php: InvalidSuperglobalConverter: Cannot find superglobal variable $_FOO
+	 */
+	public function testNonexistantSuperglobal() {
+		$converter = new InvalidSuperglobalConverter($this->info);
+		$actual = $converter->convert($this->event);
+	}
+
+	public function testFormattingTrimRight() {
+		$event = TestHelper::getInfoEvent('0123456789');
+
+		$info = new FormattingInfo();
+		$info->max = 5;
+
+		$converter = new MessageConverter($info);
+		$actual = "";
+		$converter->format($actual, $event);
+		$expected = "01234";
+		self::assertSame($expected, $actual);
+	}
+
+	public function testFormattingTrimLeft() {
+		$event = TestHelper::getInfoEvent('0123456789');
+
+		$info = new FormattingInfo();
+		$info->max = 5;
+		$info->trimLeft = true;
+
+		$converter = new MessageConverter($info);
+		$actual = "";
+		$converter->format($actual, $event);
+		$expected = "56789";
+		self::assertSame($expected, $actual);
+	}
+
+	public function testFormattingPadEmpty() {
+		$event = TestHelper::getInfoEvent('');
+
+		$info = new FormattingInfo();
+		$info->min = 5;
+
+		$converter = new MessageConverter($info);
+		$actual = "";
+		$converter->format($actual, $event);
+		$expected = "     ";
+		self::assertSame($expected, $actual);
+	}
+
+	public function testFormattingPadLeft() {
+		$event = TestHelper::getInfoEvent('0');
+
+		$info = new FormattingInfo();
+		$info->min = 5;
+
+		$converter = new MessageConverter($info);
+		$actual = "";
+		$converter->format($actual, $event);
+		$expected = "    0";
+		self::assertSame($expected, $actual);
+	}
+
+	public function testFormattingPadRight() {
+		$event = TestHelper::getInfoEvent('0');
+
+		$info = new FormattingInfo();
+		$info->min = 5;
+		$info->padLeft = false;
+
+		$converter = new MessageConverter($info);
+		$actual = "";
+		$converter->format($actual, $event);
+		$expected = "0    ";
+		self::assertSame($expected, $actual);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/README
----------------------------------------------------------------------
diff --git a/tests/src/README b/tests/src/README
new file mode 100644
index 0000000..693e23e
--- /dev/null
+++ b/tests/src/README
@@ -0,0 +1,19 @@
+All tests can be run from the root of the package by running:
+$ phpunit
+
+Tests classes are divided into groups which can be run individually:
+$ phpunit --group main
+$ phpunit --group appenders
+$ phpunit --group configurators
+$ phpunit --group filters
+$ phpunit --group helpers
+$ phpunit --group layouts
+$ phpunit --group renderers
+
+Individual test classes can be run using e.g.:
+$ phpunit src/test/php/appenders/LoggerAppenderSocketTest.php
+
+Do not use relative file paths in the tests. Absoulte paths may be constructed
+using snippets like:
+* dirname(__FILE__) . '/../path/to/file' 
+* PHPUNIT_TEMP_DIR . '/../path/to/file'

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/ReflectionUtilsTest.php
----------------------------------------------------------------------
diff --git a/tests/src/ReflectionUtilsTest.php b/tests/src/ReflectionUtilsTest.php
new file mode 100644
index 0000000..2357657
--- /dev/null
+++ b/tests/src/ReflectionUtilsTest.php
@@ -0,0 +1,91 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\ReflectionUtils;
+
+class Simple {
+    private $name;
+    private $male;
+
+    public function getName() {
+        return $this->name;
+    }
+
+    public function isMale() {
+        return $this->male;
+    }
+
+    public function setName($name) {
+        $this->name = $name;
+    }
+
+    public function setMale($male) {
+        $this->male = $male;
+    }
+}
+
+/**
+ * @group main
+ */
+class ReflectionUtilsTest extends \PHPUnit_Framework_TestCase {
+
+	public function testSimpleSet() {
+		$s = new Simple();
+		$ps = new ReflectionUtils($s);
+ 		$ps->setProperty("name", "Joe");
+ 		$ps->setProperty("male", true);
+
+ 		$this->assertEquals($s->isMale(), true);
+ 		$this->assertEquals($s->getName(), 'Joe');
+	}
+
+	public function testSimpleArraySet() {
+		$arr['xxxname'] = 'Joe';
+		$arr['xxxmale'] = true;
+
+		$s = new Simple();
+		$ps = new ReflectionUtils($s);
+ 		$ps->setProperties($arr, "xxx");
+
+ 		$this->assertEquals($s->getName(), 'Joe');
+ 		$this->assertEquals($s->isMale(), true);
+	}
+
+	public function testStaticArraySet() {
+		$arr['xxxname'] = 'Joe';
+		$arr['xxxmale'] = true;
+
+		$s = new Simple();
+		ReflectionUtils::setPropertiesByObject($s,$arr,"xxx");
+
+ 		$this->assertEquals($s->getName(), 'Joe');
+ 		$this->assertEquals($s->isMale(), true);
+	}
+	public function testCreateObject() {
+        $class = 'Apache\\Log4php\\Layouts\\SimpleLayout';
+		$object = ReflectionUtils::createObject($class);
+		$name = get_class($object);
+		self::assertEquals($name, $class);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Renderers/RendererMapTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Renderers/RendererMapTest.php b/tests/src/Renderers/RendererMapTest.php
new file mode 100644
index 0000000..3960660
--- /dev/null
+++ b/tests/src/Renderers/RendererMapTest.php
@@ -0,0 +1,249 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+use Apache\Log4php\Renderers\RendererInterface;
+use Apache\Log4php\Renderers\RendererMap;
+use Apache\Log4php\Renderers\DefaultRenderer;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggerException;
+
+/** Renders everything as 'foo'. */
+class FooRenderer implements RendererInterface {
+	public function render($input) {
+		return 'foo';
+	}
+}
+
+class InvalidCostumObjectRenderer { }
+
+class Fruit3 {
+    public $test1 = 'test1';
+    public $test2 = 'test2';
+    public $test3 = 'test3';
+}
+
+class Fruit3Descendant extends Fruit3 {
+}
+
+class FruitRenderer3 implements RendererInterface {
+    public function render($fruit) {
+		return $fruit->test1 . ',' . $fruit->test2 . ',' . $fruit->test3;
+	}
+}
+
+class SampleObject {
+}
+
+/**
+ * @group renderers
+ */
+class RendererMapTest extends \PHPUnit_Framework_TestCase {
+
+	public function testDefaults() {
+
+		$map = new RendererMap();
+		$actual = $map->getByClassName('Exception');
+		$expected = 'Apache\\Log4php\\Renderers\\ExceptionRenderer';
+		self::assertInstanceOf($expected, $actual);
+
+		// Check non-configured objects return null
+		self::assertNull($map->getByObject(new stdClass()));
+		self::assertNull($map->getByClassName('stdClass'));
+	}
+
+	public function testClear()
+	{
+		$map = new RendererMap();
+		$map->clear(); // This should clear the map and remove default renderers
+		self::assertNull($map->getByClassName('Exception'));
+	}
+
+	public function testFindAndRender()
+	{
+		$map = new RendererMap();
+		$map->addRenderer('Fruit3', 'FruitRenderer3');
+
+		$fruit = new Fruit3();
+		$descendant = new Fruit3Descendant();
+
+		// Check rendering of fruit
+		$actual = $map->findAndRender($fruit);
+		$expected = 'test1,test2,test3';
+		self::assertSame($expected, $actual);
+
+		$actual = $map->getByObject($fruit);
+		self::assertInstanceOf('FruitRenderer3', $actual);
+
+		// Check rendering of fruit's descendant
+		$actual = $map->findAndRender($descendant);
+		$expected = 'test1,test2,test3';
+		self::assertSame($expected, $actual);
+
+		$actual = $map->getByObject($descendant);
+		self::assertInstanceOf('FruitRenderer3', $actual);
+
+		// Test rendering null returns null
+		self::assertNull($map->findAndRender(null));
+	}
+
+	/**
+	 * Try adding a non-existant class as renderer.
+	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage Failed adding renderer. Rendering class [DoesNotExist] not found.
+	 */
+	public function testAddRendererError1()
+	{
+		$map = new RendererMap();
+		$map->addRenderer('Fruit3', 'DoesNotExist');
+	}
+
+	/**
+	 * Try adding a class which does not implement RendererInterface as renderer.
+	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage Failed adding renderer. Rendering class [stdClass] does not implement the RendererInterface interface.
+	 */
+	public function testAddRendererError2()
+	{
+		$map = new RendererMap();
+		$map->addRenderer('Fruit3', 'stdClass');
+	}
+
+	public function testAddRendererError3()
+	{
+		$map = new RendererMap();
+		@$map->addRenderer('Fruit3', 'stdClass');
+		self::assertNull($map->getByClassName('Fruit3'));
+
+		@$map->addRenderer('Fruit3', 'DoesNotExist');
+		self::assertNull($map->getByClassName('Fruit3'));
+	}
+
+	/**
+	 * Try setting a non-existant class as default renderer.
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Failed setting default renderer. Rendering class [DoesNotExist] not found.
+	 */
+	public function testSetDefaultRendererError1()
+	{
+		$map = new RendererMap();
+		$map->setDefaultRenderer('DoesNotExist');
+	}
+
+	/**
+	 * Try setting a class which does not implement RendererInterface as default renderer.
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Failed setting default renderer. Rendering class [stdClass] does not implement the RendererInterface interface.
+	 */
+	public function testSetDefaultRendererError2()
+	{
+		$map = new RendererMap();
+		$map->setDefaultRenderer('stdClass');
+	}
+
+	public function testSetDefaultRendererError3()
+	{
+		$map = new RendererMap();
+		$expected =  $map->getDefaultRenderer();
+
+		@$map->setDefaultRenderer('stdClass');
+		$actual = $map->getDefaultRenderer();
+		self::assertSame($expected, $actual);
+
+		@$map->setDefaultRenderer('DoesNotExist');
+		$actual = $map->getDefaultRenderer();
+		self::assertSame($expected, $actual);
+	}
+
+	public function testFetchingRenderer()
+	{
+		$map = new RendererMap();
+		$map->addRenderer('Fruit3', 'FruitRenderer3');
+	}
+
+	public function testDefaultRenderer()
+	{
+		$fruit = new Fruit3();
+
+		$map = new RendererMap();
+		$actual = $map->findAndRender($fruit);
+
+		$defaultRenderer = new DefaultRenderer();
+		$expected = $defaultRenderer->render($fruit);
+		self::assertSame($expected, $actual);
+	}
+
+	public function testOverrideDefaultRenderer()
+	{
+		$map = new RendererMap();
+		$default = $map->getDefaultRenderer();
+
+		$array = array(1, 2, 3);
+
+		$actual = $map->findAndRender($array);
+		$expected = print_r($array, true);
+		self::assertSame($actual, $expected);
+
+		// Now switch the default renderer
+		$map->setDefaultRenderer('FooRenderer');
+		$actual = $map->findAndRender($array);
+		$expected = 'foo';
+		self::assertSame($actual, $expected);
+	}
+
+	public function testGetByObjectCrap()
+	{
+		$map = new RendererMap();
+
+		// Non object input should always return null
+		self::assertNull($map->getByObject(null));
+		self::assertNull($map->getByObject(array()));
+		self::assertNull($map->getByObject('sdasda'));
+	}
+
+	public function testXMLConfig()
+	{
+		$map = Logger::getHierarchy()->getRendererMap();
+		Logger::resetConfiguration();
+
+		$expected = 'Apache\\Log4php\\Renderers\\DefaultRenderer';
+		self::assertInstanceOf($expected, $map->getDefaultRenderer());
+
+		Logger::configure(PHPUNIT_CONFIG_DIR . '/renderers/config_default_renderer.xml');
+		self::assertInstanceOf('FruitRenderer3', $map->getDefaultRenderer());
+
+		Logger::resetConfiguration();
+		self::assertInstanceOf($expected, $map->getDefaultRenderer());
+	}
+
+	public function testExceptionRenderer()
+	{
+		$ex = new LoggerException("This is a test");
+
+		$map = new RendererMap();
+		$actual = $map->findAndRender($ex);
+		$expected = (string) $ex;
+
+		self::assertSame($expected, $actual);
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/RootLoggerTest.php
----------------------------------------------------------------------
diff --git a/tests/src/RootLoggerTest.php b/tests/src/RootLoggerTest.php
new file mode 100644
index 0000000..aa6429e
--- /dev/null
+++ b/tests/src/RootLoggerTest.php
@@ -0,0 +1,67 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\RootLogger;
+
+/**
+ * @group main
+ */
+class RootLoggerTest extends \PHPUnit_Framework_TestCase {
+
+	public function testInitialSetup() {
+		$root = new RootLogger();
+		self::assertSame(Level::getLevelAll(), $root->getLevel());
+		self::assertSame(Level::getLevelAll(), $root->getEffectiveLevel());
+		self::assertSame('root', $root->getName());
+		self::assertNull($root->getParent());
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage log4php: RootLogger cannot have a parent.
+	 */
+	public function testSetParentWarning() {
+		$root = new RootLogger();
+		$logger = new Logger('test');
+		$root->setParent($logger);
+	}
+
+	public function testSetParentResult() {
+		$root = new RootLogger();
+		$logger = new Logger('test');
+		@$root->setParent($logger);
+		self::assertNull($root->getParent());
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage log4php: Cannot set RootLogger level to null.
+	 */
+	public function testNullLevelWarning() {
+		$root = new RootLogger();
+		$root->setLevel(null);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/TestHelper.php
----------------------------------------------------------------------
diff --git a/tests/src/TestHelper.php b/tests/src/TestHelper.php
new file mode 100644
index 0000000..c653eca
--- /dev/null
+++ b/tests/src/TestHelper.php
@@ -0,0 +1,160 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\Filters\AbstractFilter;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/** A set of helper functions for running tests. */
+class TestHelper {
+
+	/**
+	 * Returns a test logging event with level set to TRACE.
+	 * @return LoggingEvent
+	 */
+	public static function getTraceEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelTrace(), $message);
+	}
+
+	/**
+	 * Returns a test logging event with level set to DEBUG.
+	 * @return LoggingEvent
+	 */
+	public static function getDebugEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelDebug(), $message);
+	}
+
+	/**
+	 * Returns a test logging event with level set to INFO.
+	 * @return LoggingEvent
+	 */
+	public static function getInfoEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelInfo(), $message);
+	}
+
+	/**
+	 * Returns a test logging event with level set to WARN.
+	 * @return LoggingEvent
+	 */
+	public static function getWarnEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelWarn(), $message);
+	}
+
+	/**
+	 * Returns a test logging event with level set to ERROR.
+	 * @return LoggingEvent
+	 */
+	public static function getErrorEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelError(), $message);
+	}
+
+	/**
+	 * Returns a test logging event with level set to FATAL.
+	 * @return LoggingEvent
+	 */
+	public static function getFatalEvent($message = 'test', $logger = "test") {
+		return new LoggingEvent(__CLASS__, new Logger($logger), Level::getLevelFatal(), $message);
+	}
+
+	/**
+	 * Returns an array of logging events, one for each level, sorted ascending
+	 * by severitiy.
+	 */
+	public static function getAllEvents($message = 'test') {
+		return array(
+			self::getTraceEvent($message),
+			self::getDebugEvent($message),
+			self::getInfoEvent($message),
+			self::getWarnEvent($message),
+			self::getErrorEvent($message),
+			self::getFatalEvent($message),
+		);
+	}
+
+	/** Returns an array of all existing levels, sorted ascending by severity. */
+	public static function getAllLevels() {
+		return array(
+			Level::getLevelTrace(),
+			Level::getLevelDebug(),
+			Level::getLevelInfo(),
+			Level::getLevelWarn(),
+			Level::getLevelError(),
+			Level::getLevelFatal(),
+		);
+	}
+
+	/** Returns a string representation of a filter decision. */
+	public static function decisionToString($decision) {
+		switch($decision) {
+			case AbstractFilter::ACCEPT: return 'ACCEPT';
+			case AbstractFilter::NEUTRAL: return 'NEUTRAL';
+			case AbstractFilter::DENY: return 'DENY';
+		}
+	}
+
+	/** Returns a simple configuration with one echo appender tied to root logger. */
+	public static function getEchoConfig() {
+		return array(
+	        'threshold' => 'ALL',
+	        'rootLogger' => array(
+	            'level' => 'trace',
+	            'appenders' => array('default'),
+			),
+	        'appenders' => array(
+	            'default' => array(
+	                'class' => 'EchoAppender',
+	                'layout' => array(
+	                    'class' => 'SimpleLayout',
+					),
+				),
+			),
+		);
+	}
+
+	/** Returns a simple configuration with one echo appender using the pattern layout. */
+	public static function getEchoPatternConfig($pattern) {
+		return array(
+			'threshold' => 'ALL',
+			'rootLogger' => array(
+				'level' => 'trace',
+				'appenders' => array('default'),
+			),
+			'appenders' => array(
+				'default' => array(
+					'class' => 'EchoAppender',
+					'layout' => array(
+						'class' => 'PatternLayout',
+						'params' => array(
+							'conversionPattern' => $pattern
+						)
+					),
+				),
+			),
+		);
+	}
+}
+
+?>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/ThrowableInformationTest.php
----------------------------------------------------------------------
diff --git a/tests/src/ThrowableInformationTest.php b/tests/src/ThrowableInformationTest.php
new file mode 100644
index 0000000..9d230da
--- /dev/null
+++ b/tests/src/ThrowableInformationTest.php
@@ -0,0 +1,58 @@
+<?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.
+ *
+ * @category   tests
+ * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests;
+
+use Apache\Log4php\ThrowableInformation;
+
+class ThrowableInformationTestException extends \Exception { }
+
+/**
+ * @group main
+ */
+class ThrowableInformationTest extends \PHPUnit_Framework_TestCase {
+
+	public function testConstructor() {
+		$ex = new \Exception();
+		$tInfo = new ThrowableInformation($ex);
+
+		$result	  = $tInfo->getStringRepresentation();
+		$this->assertInternalType('array', $result);
+	}
+
+	public function testExceptionChain() {
+		$ex1 = new ThrowableInformationTestException('Message1');
+		$ex2 = new ThrowableInformationTestException('Message2', 0, $ex1);
+		$ex3 = new ThrowableInformationTestException('Message3', 0, $ex2);
+
+		$tInfo = new ThrowableInformation($ex3);
+		$result	= $tInfo->getStringRepresentation();
+		$this->assertInternalType('array', $result);
+	}
+
+	public function testGetThrowable() {
+		$ex = new ThrowableInformationTestException('Message1');
+		$tInfo = new ThrowableInformation($ex);
+		$result = $tInfo->getThrowable();
+		$this->assertEquals($ex, $result);
+	}
+}


Mime
View raw message