logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject [03/43] LOG4PHP-121: Reorganized classes into namespaces
Date Thu, 28 Nov 2013 16:03:33 GMT
http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/AppenderPoolTest.php
----------------------------------------------------------------------
diff --git a/tests/src/AppenderPoolTest.php b/tests/src/AppenderPoolTest.php
new file mode 100644
index 0000000..86ba9d9
--- /dev/null
+++ b/tests/src/AppenderPoolTest.php
@@ -0,0 +1,84 @@
+<?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\AppenderPool;
+
+use Mockery as m;
+
+/**
+ * @group filters
+ */
+class AppenderPoolTest extends \PHPUnit_Framework_TestCase {
+
+	public function setUp() {
+		AppenderPool::clear();
+	}
+
+	public function tearDown() {
+		AppenderPool::clear();
+	}
+
+ 	/**
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage log4php: Cannot add unnamed appender to pool.
+ 	 */
+	public function testAppenderHasNoName() {
+
+		$mockAppender = m::mock('Apache\\Log4php\\Appenders\\ConsoleAppender')
+			->shouldReceive('getName')->andReturn('')
+			->shouldReceive('close')
+			->mock();
+
+		AppenderPool::add($mockAppender);
+	}
+
+	public function testAppenderIsAdded() {
+
+		$mockAppender = m::mock('Apache\\Log4php\\Appenders\\ConsoleAppender')
+			->shouldReceive('getName')->andReturn('foo')
+			->shouldReceive('close')
+			->mock();
+
+		AppenderPool::add($mockAppender);
+
+		$expected = 1;
+		$actual = count(AppenderPool::getAppenders());
+		$this->assertEquals($expected, $actual);
+	}
+
+	/**
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage log4php: Appender [foo] already exists in pool. Overwriting existing appender.
+ 	 */
+	public function testDuplicateAppenderName() {
+
+		$mockAppender = m::mock('Apache\\Log4php\\Appenders\\ConsoleAppender')
+			->shouldReceive('getName')->andReturn('foo')
+			->shouldReceive('close')
+			->mock();
+
+		AppenderPool::add($mockAppender);
+		AppenderPool::add($mockAppender);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/AppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/AppenderTest.php b/tests/src/AppenderTest.php
new file mode 100644
index 0000000..d1fe009
--- /dev/null
+++ b/tests/src/AppenderTest.php
@@ -0,0 +1,181 @@
+<?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\EchoAppender;
+use Apache\Log4php\Appenders\NullAppender;
+use Apache\Log4php\Filters\DenyAllFilter;
+use Apache\Log4php\Filters\LevelMatchFilter;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * @group appenders
+ */
+class AppenderTest extends \PHPUnit_Framework_TestCase {
+
+	public function testThreshold() {
+		$appender = new EchoAppender("LoggerAppenderTest");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+
+		$warn = Level::getLevelWarn();
+		$appender->setThreshold($warn);
+		$appender->activateOptions();
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelFatal(), "testmessage");
+		ob_start();
+		$appender->doAppend($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+		$e = "FATAL - testmessage" . PHP_EOL;
+		self::assertEquals($e, $v);
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+		ob_start();
+		$appender->doAppend($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+		$e = "ERROR - testmessage" . PHP_EOL;
+		self::assertEquals($e, $v);
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelWarn(), "testmessage");
+		ob_start();
+		$appender->doAppend($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+		$e = "WARN - testmessage" . PHP_EOL;
+		self::assertEquals($e, $v);
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelInfo(), "testmessage");
+		ob_start();
+		$appender->doAppend($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+		$e = "";
+		self::assertEquals($e, $v);
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelDebug(), "testmessage");
+		ob_start();
+		$appender->doAppend($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+		$e = "";
+		self::assertEquals($e, $v);
+    }
+
+    public function testGetThreshold() {
+		$appender = new EchoAppender("LoggerAppenderTest");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+
+		$warn = Level::getLevelWarn();
+		$appender->setThreshold($warn);
+
+		$a = $appender->getThreshold();
+		self::assertEquals($warn, $a);
+    }
+
+    public function testSetStringThreshold() {
+		$appender = new EchoAppender("LoggerAppenderTest");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+
+		$warn = Level::getLevelWarn();
+		$appender->setThreshold('WARN');
+		$a = $appender->getThreshold();
+		self::assertEquals($warn, $a);
+
+		$e = Level::getLevelFatal();
+		$appender->setThreshold('FATAL');
+		$a = $appender->getThreshold();
+		self::assertEquals($e, $a);
+
+		$e = Level::getLevelError();
+		$appender->setThreshold('ERROR');
+		$a = $appender->getThreshold();
+		self::assertEquals($e, $a);
+
+		$e = Level::getLevelDebug();
+		$appender->setThreshold('DEBUG');
+		$a = $appender->getThreshold();
+		self::assertEquals($e, $a);
+
+		$e = Level::getLevelInfo();
+		$appender->setThreshold('INFO');
+		$a = $appender->getThreshold();
+		self::assertEquals($e, $a);
+    }
+
+     public function testSetFilter() {
+		$appender = new EchoAppender("LoggerAppenderTest");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+
+		$filter  = new DenyAllFilter();
+		$appender->addFilter($filter);
+
+		$filter2  = new LevelMatchFilter();
+		$appender->addFilter($filter2);
+
+		$first = $appender->getFilter();
+		self::assertEquals($first, $filter);
+
+		$next = $first->getNext();
+		self::assertEquals($next, $filter2);
+
+		$appender->clearFilters();
+		$nullfilter = $appender->getFilter();
+		self::assertNull($nullfilter);
+    }
+
+    public function testInstanciateWithLayout() {
+    	$appender = new EchoAppender("LoggerAppenderTest");
+
+    	$expected = "Apache\\Log4php\\Layouts\\SimpleLayout";
+    	$actual = $appender->getLayout();
+    	$this->assertInstanceof($expected, $actual);
+    }
+
+    public function testOverwriteLayout() {
+    	$layout = new SimpleLayout();
+    	$appender = new EchoAppender("LoggerAppenderTest");
+    	$appender->setLayout($layout);
+
+    	$actual = $appender->getLayout();
+    	$this->assertEquals($layout, $actual);
+    }
+
+    public function testRequiresNoLayout() {
+    	$appender = new NullAppender("LoggerAppenderTest");
+
+    	$actual = $appender->getLayout();
+    	$this->assertNull($actual);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/ConsoleAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/ConsoleAppenderTest.php b/tests/src/Appenders/ConsoleAppenderTest.php
new file mode 100644
index 0000000..a99a407
--- /dev/null
+++ b/tests/src/Appenders/ConsoleAppenderTest.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\Appenders;
+
+use Apache\Log4php\Logger;
+use Apache\Log4php\Appenders\ConsoleAppender;
+
+/**
+ * @group appenders
+ */
+class ConsoleAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	private $config = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'ConsoleAppender',
+				'layout' => array(
+					'class' => 'PatternLayout',
+					'params' => array(
+						// Intentionally blank so output doesn't clutter phpunit output
+						'conversionPattern' => ''
+					)
+				),
+			)
+		)
+	);
+
+	public function testRequiresLayout() {
+		$appender = new ConsoleAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+    public function testAppendDefault() {
+    	Logger::configure($this->config);
+    	$log = Logger::getRootLogger();
+
+    	$expected = ConsoleAppender::STDOUT;
+    	$actual = $log->getAppender('default')->getTarget();
+    	$this->assertSame($expected, $actual);
+
+    	$log->info("hello");
+    }
+
+    public function testAppendStdout() {
+    	$this->config['appenders']['default']['params']['target'] = 'stdout';
+
+    	Logger::configure($this->config);
+    	$log = Logger::getRootLogger();
+
+    	$expected = ConsoleAppender::STDOUT;
+    	$actual = $log->getAppender('default')->getTarget();
+    	$this->assertSame($expected, $actual);
+
+    	$log->info("hello");
+    }
+
+    public function testAppendStderr() {
+    	$this->config['appenders']['default']['params']['target'] = 'stderr';
+    	Logger::configure($this->config);
+    	$log = Logger::getRootLogger();
+    	$expected = ConsoleAppender::STDERR;
+
+    	$actual = $log->getAppender('default')->getTarget();
+    	$this->assertSame($expected, $actual);
+
+    	$log->info("hello");
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/DailyFileAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/DailyFileAppenderTest.php b/tests/src/Appenders/DailyFileAppenderTest.php
new file mode 100644
index 0000000..e5f3acf
--- /dev/null
+++ b/tests/src/Appenders/DailyFileAppenderTest.php
@@ -0,0 +1,194 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\DailyFileAppender;
+use Apache\Log4php\Level;
+use Apache\Log4php\LoggingEvent;
+use Apache\Log4php\Tests\TestHelper;
+
+/**
+ * @group appenders
+ */
+class DailyFileAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	protected function setUp() {
+		@unlink(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date('Ymd'));
+		@unlink(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date('Y'));
+	}
+
+	public function testRequiresLayout() {
+		$appender = new DailyFileAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testDefaultLayout() {
+		$appender = new DailyFileAppender();
+		$actual = $appender->getLayout();
+		self::assertInstanceOf('Apache\\Log4php\\Layouts\\SimpleLayout', $actual);
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Required parameter 'file' not set.
+	 */
+	public function testRequiredParamWarning1() {
+		$appender = new DailyFileAppender();
+		$appender->activateOptions();
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Required parameter 'datePattern' not set.
+	 */
+	public function testRequiredParamWarning2() {
+		$appender = new DailyFileAppender();
+		$appender->setFile('file.log');
+		$appender->setDatePattern('');
+		$appender->activateOptions();
+	}
+
+	public function testGetDatePattern() {
+		$appender = new DailyFileAppender();
+
+		// Default pattern
+		$actual = $appender->getDatePattern();
+		self::assertEquals('Ymd', $actual);
+
+		// Custom pattern
+		$appender->setDatePattern('xyz');
+		$actual = $appender->getDatePattern();
+		self::assertEquals('xyz', $actual);
+	}
+
+	/**
+	 * For greater code coverage!
+	 * Override the warning so remaining code is reached.
+	 */
+	public function testRequiredParamWarning3() {
+		$appender = new DailyFileAppender();
+		$appender->setFile('file.log');
+		$appender->setDatePattern('');
+		@$appender->activateOptions();
+	}
+
+	public function testLazyFileOpen() {
+		$event = TestHelper::getWarnEvent("my message");
+		$file = PHPUNIT_TEMP_DIR . '/lazy-file.%s.log';
+		$pattern = 'Y-m-d';
+
+		$date = date($pattern, $event->getTimeStamp());
+		$path =  PHPUNIT_TEMP_DIR . "/lazy-file.$date.log";
+
+		if (file_exists($path)) {
+			unlink($path);
+		}
+
+		$appender = new DailyFileAppender();
+		$appender->setFile($file);
+		$appender->setDatePattern('Y-m-d');
+		$appender->activateOptions();
+
+		// File should not exist before first append
+		self::assertFileNotExists($path);
+		$appender->append($event);
+		self::assertFileExists($path);
+	}
+
+	public function testRollover()
+	{
+		$message = uniqid();
+		$level = Level::getLevelDebug();
+
+		$file = PHPUNIT_TEMP_DIR . '/lazy-file.%s.log';
+		$pattern = 'Y-m-d';
+
+		// Get some timestamps for events - different date for each
+		$ts1 = mktime(10, 0, 0, 7, 3, 1980);
+		$ts2 = mktime(10, 0, 0, 7, 4, 1980);
+		$ts3 = mktime(10, 0, 0, 7, 5, 1980);
+
+		$e1 = new LoggingEvent(__CLASS__, 'test', $level, $message, $ts1);
+		$e2 = new LoggingEvent(__CLASS__, 'test', $level, $message, $ts2);
+		$e3 = new LoggingEvent(__CLASS__, 'test', $level, $message, $ts3);
+
+		// Expected paths
+		$path1 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-03.log';
+		$path2 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-04.log';
+		$path3 = PHPUNIT_TEMP_DIR . '/lazy-file.1980-07-05.log';
+
+		@unlink($path1);
+		@unlink($path2);
+		@unlink($path3);
+
+		$appender = new DailyFileAppender();
+		$appender->setFile($file);
+		$appender->setDatePattern('Y-m-d');
+		$appender->activateOptions();
+
+		$appender->append($e1);
+		$appender->append($e2);
+		$appender->append($e3);
+
+		$actual1 = file_get_contents($path1);
+		$actual2 = file_get_contents($path2);
+		$actual3 = file_get_contents($path3);
+
+		$expected1 = "DEBUG - $message" . PHP_EOL;
+		$expected2 = "DEBUG - $message" . PHP_EOL;
+		$expected3 = "DEBUG - $message" . PHP_EOL;
+
+		self::assertSame($expected1, $actual1);
+		self::assertSame($expected2, $actual2);
+		self::assertSame($expected3, $actual3);
+	}
+
+	public function testSimpleLogging() {
+		$event = TestHelper::getWarnEvent("my message");
+
+		$appender = new DailyFileAppender();
+		$appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.%s');
+		$appender->activateOptions();
+		$appender->append($event);
+		$appender->close();
+
+		$actual = file_get_contents(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date("Ymd"));
+		$expected = "WARN - my message".PHP_EOL;
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testChangedDateFormat() {
+		$event = TestHelper::getWarnEvent("my message");
+
+		$appender = new DailyFileAppender();
+		$appender->setDatePattern('Y');
+		$appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.%s');
+		$appender->activateOptions();
+		$appender->append($event);
+		$appender->close();
+
+		$actual = file_get_contents(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date("Y"));
+		$expected = "WARN - my message".PHP_EOL;
+		self::assertEquals($expected, $actual);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/EchoAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/EchoAppenderTest.php b/tests/src/Appenders/EchoAppenderTest.php
new file mode 100644
index 0000000..57f2c12
--- /dev/null
+++ b/tests/src/Appenders/EchoAppenderTest.php
@@ -0,0 +1,170 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\EchoAppender;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * @group appenders
+ */
+class EchoAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	private $config1 = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'EchoAppender',
+				'layout' => array(
+					'class' => 'SimpleLayout'
+				),
+			)
+		)
+	);
+
+	private $config2 = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'EchoAppender',
+				'layout' => array(
+					'class' => 'SimpleLayout'
+				),
+				'params' => array(
+					'htmlLineBreaks' => true
+				)
+			)
+		)
+	);
+
+	private $config3 = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'EchoAppender',
+				'layout' => array(
+					'class' => 'SimpleLayout'
+				),
+				'params' => array(
+					'htmlLineBreaks' => 'foo'
+				)
+			)
+		)
+	);
+
+	public function testAppend() {
+		Logger::configure($this->config1);
+		$log = Logger::getRootLogger();
+
+		$hlb = $log->getAppender('default')->getHtmlLineBreaks();
+		$this->assertSame(false, $hlb);
+
+		ob_start();
+		$log->info("This is a test");
+		$log->debug("And this too");
+		$actual = ob_get_clean();
+		$expected = "INFO - This is a test" . PHP_EOL . "DEBUG - And this too". PHP_EOL;
+
+		$this->assertSame($expected, $actual);
+	}
+
+	public function testHtmlLineBreaks() {
+		Logger::configure($this->config2);
+		$log = Logger::getRootLogger();
+
+		$hlb = $log->getAppender('default')->getHtmlLineBreaks();
+		$this->assertSame(true, $hlb);
+
+		ob_start();
+		$log->info("This is a test" . PHP_EOL . "With more than one line");
+		$log->debug("And this too");
+		$actual = ob_get_clean();
+		$expected = "INFO - This is a test<br />" . PHP_EOL . "With more than one line<br />" . PHP_EOL . "DEBUG - And this too<br />" . PHP_EOL;
+
+		$this->assertSame($expected, $actual);
+	}
+
+// 	public function testHtmlLineBreaksInvalidOption() {
+// 		Logger::configure($this->config3);
+// 	}
+
+
+	public function testEcho() {
+		$appender = new EchoAppender("myname ");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+		$appender->activateOptions();
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+
+		$expected = "ERROR - testmessage" . PHP_EOL;
+		ob_start();
+		$appender->append($event);
+		$actual = ob_get_clean();
+
+		self::assertEquals($expected, $actual);
+	}
+
+	public function testRequiresLayout() {
+		$appender = new EchoAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testEchoHtml() {
+		$appender = new EchoAppender("myname ");
+		$appender->setHtmlLineBreaks(true);
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+		$appender->activateOptions();
+
+		// Single line message
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+
+		$expected = "ERROR - testmessage<br />" . PHP_EOL;
+		ob_start();
+		$appender->append($event);
+		$actual = ob_get_clean();
+		self::assertEquals($expected, $actual);
+
+		// Multi-line message
+		$msg = "This message\nis in several lines\r\nto test various line breaks.";
+		$expected = "ERROR - This message<br />\nis in several lines<br />\r\nto test various line breaks.<br />" . PHP_EOL;
+
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), $msg);
+		ob_start();
+		$appender->append($event);
+		$actual = ob_get_clean();
+		self::assertEquals($expected, $actual);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/FileAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/FileAppenderTest.php b/tests/src/Appenders/FileAppenderTest.php
new file mode 100644
index 0000000..e8ed539
--- /dev/null
+++ b/tests/src/Appenders/FileAppenderTest.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
+ * @package	   log4php
+ * @license	   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+ * @link       http://logging.apache.org/log4php
+ */
+
+namespace Apache\Log4php\Tests\Appenders;
+
+use Apache\Log4php\Appenders\FileAppender;
+use Apache\Log4php\Logger;
+use Apache\Log4php\Tests\TestHelper;
+
+/**
+ * @group appenders
+ */
+class FileAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	private $config1 = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'FileAppender',
+				'layout' => array(
+					'class' => 'SimpleLayout'
+				),
+				'params' => array()
+			)
+		)
+	);
+
+	private $testPath;
+
+	public function __construct() {
+		$this->testPath = PHPUNIT_TEMP_DIR . '/TEST.txt';
+	}
+
+	public function setUp() {
+		Logger::resetConfiguration();
+		if(file_exists($this->testPath)) {
+			unlink($this->testPath);
+		}
+	}
+
+	public function tearDown() {
+		Logger::resetConfiguration();
+		if(file_exists($this->testPath)) {
+			unlink($this->testPath);
+		}
+	}
+
+	public function testRequiresLayout() {
+		$appender = new FileAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testActivationDoesNotCreateTheFile() {
+		$path = PHPUNIT_TEMP_DIR . "/doesnotexisthopefully.log";
+		@unlink($path);
+		$appender = new FileAppender();
+		$appender->setFile($path);
+		$appender->activateOptions();
+
+		self::assertFalse(file_exists($path));
+
+		$event = TestHelper::getInfoEvent('bla');
+		$appender->append($event);
+
+		self::assertTrue(file_exists($path));
+	}
+
+	public function testSimpleLogging() {
+		$config = $this->config1;
+		$config['appenders']['default']['params']['file'] = $this->testPath;
+
+		Logger::configure($config);
+
+		$logger = Logger::getRootLogger();
+		$logger->info('This is a test');
+
+		$expected = "INFO - This is a test" . PHP_EOL;
+		$actual = file_get_contents($this->testPath);
+		$this->assertSame($expected, $actual);
+	}
+
+	public function testAppendFlagTrue() {
+		$config = $this->config1;
+		$config['appenders']['default']['params']['file'] = $this->testPath;
+		$config['appenders']['default']['params']['append'] = true;
+
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+		$logger->info('This is a test');
+
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+		$logger->info('This is a test');
+
+		$expected = "INFO - This is a test" . PHP_EOL . "INFO - This is a test" . PHP_EOL;
+		$actual = file_get_contents($this->testPath);
+		$this->assertSame($expected, $actual);
+	}
+
+	public function testAppendFlagFalse() {
+		$config = $this->config1;
+		$config['appenders']['default']['params']['file'] = $this->testPath;
+		$config['appenders']['default']['params']['append'] = false;
+
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+		$logger->info('This is a test');
+
+		Logger::configure($config);
+		$logger = Logger::getRootLogger();
+		$logger->info('This is a test');
+
+		$expected = "INFO - This is a test" . PHP_EOL;
+		$actual = file_get_contents($this->testPath);
+		$this->assertSame($expected, $actual);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/MailAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/MailAppenderTest.php b/tests/src/Appenders/MailAppenderTest.php
new file mode 100644
index 0000000..73c7e83
--- /dev/null
+++ b/tests/src/Appenders/MailAppenderTest.php
@@ -0,0 +1,64 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\MailAppender;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * @group appenders
+ */
+class MailAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	public function testRequiresLayout() {
+		$appender = new MailAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testMail() {
+		$appender = new MailAppender("myname ");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+		$appender->setDry(true);
+		$appender->setTo('test@example.com');
+		$appender->setFrom('Testsender');
+
+		$appender->activateOptions();
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+		$event2 = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage2");
+
+		ob_start();
+		$appender->append($event);
+		$appender->append($event2);
+		$appender->close();
+		$v = ob_get_contents();
+		ob_end_clean();
+
+		$e = "DRY MODE OF MAIL APP.: Send mail to: test@example.com with content: ERROR - testmessage".PHP_EOL."ERROR - testmessage2".PHP_EOL;
+		self::assertEquals($e, $v);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/MailEventAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/MailEventAppenderTest.php b/tests/src/Appenders/MailEventAppenderTest.php
new file mode 100644
index 0000000..2199f83
--- /dev/null
+++ b/tests/src/Appenders/MailEventAppenderTest.php
@@ -0,0 +1,86 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\MailEventAppender;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * @group appenders
+ */
+class MailEventAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	public function testRequiresLayout() {
+		$appender = new MailEventAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testMail() {
+		$appender = new MailEventAppender("myname");
+
+		$layout = new SimpleLayout();
+		$appender->setLayout($layout);
+		$appender->setDry(true);
+		$appender->setTo('test@example.com');
+		$appender->setFrom('Testsender');
+
+		$appender->activateOptions();
+		$event = new LoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+
+		ob_start();
+		$appender->append($event);
+		$v = ob_get_contents();
+		ob_end_clean();
+
+		$e = "DRY MODE OF MAIL APP.: Send mail to: test@example.com with additional headers 'From: Testsender' and content: ERROR - testmessage".PHP_EOL;
+		self::assertEquals($e, $v);
+		$appender->close();
+	}
+
+	/**
+	 * Check an error is reported if 'to' is not set.
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Required parameter 'to' not set.
+	 */
+	public function testEmptyTo() {
+		$appender = new MailEventAppender("myname");
+		$appender->setLayout(new SimpleLayout());
+		$appender->setFrom('info@example.com');
+		$appender->activateOptions();
+	}
+
+	/**
+	 * Check an error is reported if 'from' is not set.
+	 * @expectedException PHPUnit_Framework_Error
+	 * @expectedExceptionMessage Required parameter 'from' not set.
+	 */
+	public function testEmptyFrom() {
+		$appender = new MailEventAppender("myname");
+		$appender->setLayout(new SimpleLayout());
+		$appender->setTo('info@example.com');
+		$appender->activateOptions();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/MongoDBAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/MongoDBAppenderTest.php b/tests/src/Appenders/MongoDBAppenderTest.php
new file mode 100644
index 0000000..e4622dd
--- /dev/null
+++ b/tests/src/Appenders/MongoDBAppenderTest.php
@@ -0,0 +1,213 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\MongoDBAppender;
+use Apache\Log4php\LoggingEvent;
+use Apache\Log4php\Logger;
+use Apache\Log4php\Level;
+use Apache\Log4php\Tests\TestHelper;
+
+/**
+ * Testclass for the MongoDB appender.
+ *
+ * This class has been originally contributed from Vladimir Gorej
+ * (http://github.com/log4mongo/log4mongo-php).
+ *
+ * @group appenders
+ */
+class MongoDBAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	protected $appender;
+	protected $event;
+
+	protected function setUp() {
+		if (!extension_loaded('mongo')) {
+			$this->markTestSkipped(
+				'The Mongo extension is not available.'
+			);
+		} else {
+			$this->appender = new MongoDBAppender('mongo_appender');
+			$this->event = TestHelper::getErrorEvent('mongo logging event', 'test_mongo');
+		}
+	}
+
+	protected function tearDown() {
+		unset($this->appender);
+	}
+
+	public function testHost() {
+		$expected = 'mongodb://localhost';
+		$this->appender->setHost($expected);
+		$result = $this->appender->getHost();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testPort() {
+		$expected = 27017;
+		$this->appender->setPort($expected);
+		$result = $this->appender->getPort();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testDatabaseName() {
+		$expected = 'log4php_mongodb';
+		$this->appender->setDatabaseName($expected);
+		$result	= $this->appender->getDatabaseName();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testCollectionName() {
+		$expected = 'logs';
+		$this->appender->setCollectionName($expected);
+		$result = $this->appender->getCollectionName();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testUserName() {
+		$expected = 'char0n';
+		$this->appender->setUserName($expected);
+		$result = $this->appender->getUserName();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testPassword() {
+		$expected = 'secret pass';
+		$this->appender->setPassword($expected);
+		$result	= $this->appender->getPassword();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testTimeout() {
+		$expected = 4000;
+		$this->appender->setTimeout($expected);
+		$result	= $this->appender->getTimeout();
+		$this->assertEquals($expected, $result);
+	}
+
+	public function testActivateOptions() {
+		$this->appender->activateOptions();
+		$this->assertInstanceOf('Mongo', $this->appender->getConnection());
+		$this->assertInstanceOf('MongoCollection', $this->appender->getCollection());
+	}
+
+	public function testActivateOptionsNoCredentials() {
+		$this->appender->setUserName(null);
+		$this->appender->setPassword(null);
+		$this->appender->activateOptions();
+		$this->assertInstanceOf('Mongo', $this->appender->getConnection());
+		$this->assertInstanceOf('MongoCollection', $this->appender->getCollection());
+	}
+
+	public function testFormat() {
+		$this->appender->activateOptions();
+		$record = $this->logOne($this->event);
+
+		$this->assertEquals('ERROR', $record['level']);
+		$this->assertEquals('mongo logging event', $record['message']);
+		$this->assertEquals('test_mongo', $record['loggerName']);
+
+		$this->assertEquals('NA', $record['fileName']);
+		$this->assertEquals('getLocationInformation', $record['method']);
+		$this->assertEquals('NA', $record['lineNumber']);
+		$this->assertEquals('Apache\\Log4php\\LoggingEvent', $record['className']);
+
+		$this->assertTrue(is_int($record['thread']));
+		$this->assertSame(getmypid(), $record['thread']);
+		$this->assertTrue(is_int($record['lineNumber']) || $record['lineNumber'] == 'NA');
+	}
+
+	public function testFormatThrowableInfo() {
+		$this->appender->activateOptions();
+		$event = new LoggingEvent(
+			'testFqcn',
+			new Logger('test.Logger'),
+			Level::getLevelWarn(),
+			'test message',
+			microtime(true),
+			new \Exception('test exception', 1)
+		);
+
+		$record = $this->logOne($event);
+
+		$this->assertArrayHasKey('exception', $record);
+		$this->assertEquals(1, $record['exception']['code']);
+		$this->assertEquals('test exception', $record['exception']['message']);
+
+		$this->assertContains('[internal function]: ' . __CLASS__, $record['exception']['stackTrace']);
+	}
+
+	 public function testFormatThrowableInfoWithInnerException() {
+
+		 // Skip test if PHP version is lower than 5.3.0 (no inner exception support)
+		 if (version_compare(PHP_VERSION, '5.3.0') < 0) {
+			 $this->markTestSkipped();
+		 }
+
+		 $this->appender->activateOptions();
+		 $event = new LoggingEvent(
+			 'testFqcn',
+			 new Logger('test.Logger'),
+			 Level::getLevelWarn(),
+			 'test message',
+			 microtime(true),
+			 new \Exception('test exception', 1, new \Exception('test exception inner', 2))
+		 );
+
+		 $record = $this->logOne($event);
+
+		 $this->assertArrayHasKey('exception', $record);
+		 $this->assertEquals(1, $record['exception']['code']);
+		 $this->assertEquals('test exception', $record['exception']['message']);
+		 $this->assertContains('[internal function]: ' . __CLASS__, $record['exception']['stackTrace']);
+
+		 $this->assertArrayHasKey('innerException', $record['exception']);
+		 $this->assertEquals(2, $record['exception']['innerException']['code']);
+		 $this->assertEquals('test exception inner', $record['exception']['innerException']['message']);
+	 }
+
+
+	 public function testClose() {
+		 $this->appender->activateOptions();
+		 $this->assertInstanceOf('Mongo', $this->appender->getConnection());
+		 $this->assertInstanceOf('MongoCollection', $this->appender->getCollection());
+		 $this->appender->close();
+		 $this->assertNull($this->appender->getConnection());
+		 $this->assertNull($this->appender->getCollection());
+	 }
+
+	/**
+	 * Logs the event and returns the record from the database.
+	 * @param LoggingEvent $event
+	 * @return array
+	 */
+	private function logOne($event)
+	{
+		$collection = $this->appender->getCollection();
+		$collection->drop();
+		$this->appender->append($event);
+		$record = $collection->findOne();
+		$this->assertNotNull($record, 'Could not read the record from the database.');
+		return $record;
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/NullAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/NullAppenderTest.php b/tests/src/Appenders/NullAppenderTest.php
new file mode 100644
index 0000000..5c7a96e
--- /dev/null
+++ b/tests/src/Appenders/NullAppenderTest.php
@@ -0,0 +1,51 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\NullAppender;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * @group appenders
+ */
+class NullAppenderTest extends \PHPUnit_Framework_TestCase {
+	/**
+	 * The Null appender does nothing - nothing to assert.
+	 * Just here for the sake of completness and a good testing ratio :-)
+	 */
+	public function testActivateOptions() {
+        $event = new LoggingEvent("LoggerAppenderNullTest", new Logger("TEST"), Level::getLevelInfo(), "testmessage");
+
+		$appender = new NullAppender("TEST");
+		$appender->activateOptions();
+		$appender->append($event);
+		$appender->close();
+    }
+
+	public function testRequiresLayout() {
+		$appender = new NullAppender();
+		self::assertFalse($appender->requiresLayout());
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/PDOAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/PDOAppenderTest.php b/tests/src/Appenders/PDOAppenderTest.php
new file mode 100644
index 0000000..b325e04
--- /dev/null
+++ b/tests/src/Appenders/PDOAppenderTest.php
@@ -0,0 +1,170 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\PDOAppender;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+use PDO;
+
+/**
+ * @group appenders
+ */
+class PDOAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	const FILENAME = 'pdotest.sqlite';
+	private static $dsn;
+	private static $file;
+
+	public static function setUpBeforeClass() {
+
+		self::$file = PHPUNIT_TEMP_DIR . '/' . self::FILENAME;
+		self::$dsn = 'sqlite:' . self::$file;
+
+		if(extension_loaded('pdo_sqlite')) {
+			$drop = 'DROP TABLE IF EXISTS log4php_log;';
+			$create = 'CREATE TABLE log4php_log (
+				timestamp VARCHAR(256),
+				logger VARCHAR(256),
+				level VARCHAR(32),
+				message VARCHAR(4000),
+				thread INTEGER,
+				file VARCHAR(255),
+				line VARCHAR(10)
+			);';
+
+			$pdo = new PDO(self::$dsn);
+			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+			$pdo->exec($drop);
+			$pdo->exec($create);
+		}
+	}
+
+	/** To start with an empty database for each single test. */
+	public function setUp() {
+		if(!extension_loaded('pdo_sqlite')) {
+			self::markTestSkipped("Please install 'pdo_sqlite' in order to run this test");
+		}
+	}
+
+	/** Clean up after the last test was run. */
+	public static function tearDownAfterClass() {
+		@unlink(self::$file);
+	}
+
+	public function testRequiresLayout() {
+		$appender = new PDOAppender();
+		self::assertFalse($appender->requiresLayout());
+	}
+
+	/** Tests new-style logging using prepared statements and the default SQL definition. */
+	public function testSimpleWithDefaults() {
+		// Log event
+		$event = new LoggingEvent("LoggerAppenderPDOTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+		$appender = new PDOAppender("myname");
+		$appender->setDSN(self::$dsn);
+		$appender->activateOptions();
+		$appender->append($event);
+		$appender->close();
+
+		// Test the default pattern
+		$db = new PDO(self::$dsn);
+		$query = "SELECT * FROM log4php_log";
+		$sth = $db->query($query);
+		$row = $sth->fetch(PDO::FETCH_NUM);
+
+		self::assertTrue(is_array($row), "No rows found.");
+		self::assertEquals(7, count($row));
+		self::assertEquals(1, preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $row[0])); // datetime
+		self::assertEquals('TEST', $row[1]); // logger name
+		self::assertEquals('ERROR', $row[2]); // level
+		self::assertEquals('testmessage', $row[3]); // message
+		if (function_exists('posix_getpid')) {
+			self::assertEquals(posix_getpid(), $row[4]); // process id
+		}
+		self::assertEquals('NA', $row[5]); // file, NA due to phpunit magic
+		self::assertEquals('NA', $row[6]); // line, NA due to phpunit magic
+	}
+
+
+	/** Tests new style prepared statment logging with customized SQL. */
+	public function testCustomizedSql() {
+
+		$dateFormat = "Y-m-d H:i:s";
+
+		// Prepare appender
+		$appender = new PDOAppender("myname");
+		$appender->setDSN(self::$dsn);
+		$appender->setInsertSql("INSERT INTO log4php_log (file, line, thread, timestamp, logger, level, message) VALUES (?,?,?,?,?,?,?)");
+		$appender->setInsertPattern("%F,%L,%t,%d\{$dateFormat\},%c,%p,%m");
+		$appender->activateOptions();
+
+		// Action!
+		$event = new LoggingEvent("LoggerAppenderPDOTest2", new Logger("TEST"), Level::getLevelError(), "testmessage");
+		$appender->append($event);
+
+		// Check
+		$db = new PDO(self::$dsn);
+		$result = $db->query("SELECT * FROM log4php_log");
+		$row = $result->fetch(PDO::FETCH_OBJ);
+		self::assertTrue(is_object($row));
+		self::assertEquals("NA", $row->file); // "NA" due to phpunit magic
+		self::assertEquals("NA", $row->line); // "NA" due to phpunit magic
+		if (function_exists('posix_getpid')) {
+			self::assertEquals(posix_getpid(), $row->thread);
+		}
+		self::assertEquals(1, preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $row->timestamp));
+		self::assertEquals('TEST', $row->logger);
+		self::assertEquals('ERROR', $row->level);
+		self::assertEquals('testmessage', $row->message);
+	}
+
+	/**
+	 * Tests a warning is shown when connecting to invalid dns.
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage invalid data source name
+	 */
+	public function testException() {
+		$dsn = 'doenotexist';
+		$appender = new PDOAppender("myname");
+		$appender->setDSN($dsn);
+		$appender->activateOptions();
+	}
+
+	/**
+	 * Check whether close() actually closes the database connection.
+	 */
+	public function testClose() {
+		$event = new LoggingEvent("LoggerAppenderPDOTest", new Logger("TEST"), Level::getLevelError(), "testmessage");
+
+		$appender = new PDOAppender("myname");
+		$appender->setDSN(self::$dsn);
+		$appender->activateOptions();
+		$appender->append($event);
+		$appender->close();
+
+		self::assertNull($appender->getDatabaseHandle());
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/PhpAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/PhpAppenderTest.php b/tests/src/Appenders/PhpAppenderTest.php
new file mode 100644
index 0000000..0653f65
--- /dev/null
+++ b/tests/src/Appenders/PhpAppenderTest.php
@@ -0,0 +1,98 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\PhpAppender;
+use Apache\Log4php\Logger;
+
+/**
+ * @group appenders
+ */
+class PhpAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	public static $expectedMessage;
+
+	public static $expectedError;
+
+	private $config = array(
+		'rootLogger' => array(
+			'appenders' => array('default'),
+			'level' => 'trace'
+		),
+		'appenders' => array(
+			'default' => array(
+				'class' => 'PhpAppender',
+				'layout' => array(
+					'class' => 'SimpleLayout'
+				),
+			)
+		)
+	);
+
+    protected function setUp() {
+    	$that = $this; // hack for PHP 5.3
+		set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($that) {
+			$that::assertEquals($that::$expectedError, $errno);
+			$that::assertEquals($that::$expectedMessage, $errstr);
+		});
+	}
+
+	public function testRequiresLayout() {
+		$appender = new PhpAppender();
+		$this->assertTrue($appender->requiresLayout());
+	}
+
+	public function testPhp() {
+		Logger::configure($this->config);
+		$logger = Logger::getRootLogger();
+
+
+		self::$expectedError = E_USER_ERROR;
+		self::$expectedMessage = "FATAL - This is a test" . PHP_EOL;
+		$logger->fatal("This is a test");
+
+		self::$expectedError = E_USER_ERROR;
+		self::$expectedMessage = "ERROR - This is a test" . PHP_EOL;
+		$logger->error("This is a test");
+
+		self::$expectedError = E_USER_WARNING;
+		self::$expectedMessage = "WARN - This is a test" . PHP_EOL;
+		$logger->warn("This is a test");
+
+		self::$expectedError = E_USER_NOTICE;
+		self::$expectedMessage = "INFO - This is a test" . PHP_EOL;
+		$logger->info("This is a test");
+
+		self::$expectedError = E_USER_NOTICE;
+		self::$expectedMessage = "DEBUG - This is a test" . PHP_EOL;
+		$logger->debug("This is a test");
+
+		self::$expectedError = E_USER_NOTICE;
+		self::$expectedMessage = "TRACE - This is a test" . PHP_EOL;
+		$logger->trace("This is a test");
+    }
+
+    protected function tearDown() {
+		restore_error_handler();
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/RollingFileAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/RollingFileAppenderTest.php b/tests/src/Appenders/RollingFileAppenderTest.php
new file mode 100644
index 0000000..d284f3c
--- /dev/null
+++ b/tests/src/Appenders/RollingFileAppenderTest.php
@@ -0,0 +1,212 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\RollingFileAppender;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Tests\TestHelper;
+use Apache\Log4php\LoggingEvent;
+use Apache\Log4php\Logger;
+use Apache\Log4php\Level;
+
+/**
+ * @group appenders
+ */
+class RollingFileAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	const WARNING_MASSAGE = 'WARN - my messageXYZ';
+
+	protected function setUp() {
+		@unlink(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt');
+		@unlink(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.1');
+		@unlink(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.2');
+	}
+
+	public function testRequiresLayout() {
+		$appender = new RollingFileAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testMaxFileSize() {
+		$appender = new RollingFileAppender("mylogger");
+
+		$appender->setMaxFileSize('1KB');
+		self::assertEquals(1024, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('2KB');
+		self::assertEquals(2048, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('1MB');
+		self::assertEquals(1048576, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('3MB');
+		self::assertEquals(3145728, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('1GB');
+		self::assertEquals(1073741824, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('10000');
+		self::assertEquals(10000, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('100.5');
+		self::assertEquals(100, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('1000.6');
+		self::assertEquals(1000, $appender->getMaxFileSize());
+
+		$appender->setMaxFileSize('1.5MB');
+		self::assertEquals(1572864, $appender->getMaxFileSize());
+	}
+
+	/**
+	 * @return RollingFileAppender
+	 */
+	private function createRolloverAppender() {
+		$layout = new SimpleLayout();
+
+		$appender = new RollingFileAppender("mylogger");
+		$appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt');
+		$appender->setLayout($layout);
+		$appender->setMaxFileSize('1KB');
+		$appender->setMaxBackupIndex(2);
+		$appender->activateOptions();
+
+		return $appender;
+	}
+
+	public function testSimpleLogging() {
+		$appender = $this->createRolloverAppender();
+
+		$event = TestHelper::getWarnEvent("my message123");
+
+		for($i = 0; $i < 1000; $i++) {
+			$appender->append($event);
+		}
+
+		$appender->append(TestHelper::getWarnEvent("my messageXYZ"));
+
+		$appender->close();
+
+		$file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt';
+		$data = file($file);
+		$line = $data[count($data)-1];
+		$e = "WARN - my messageXYZ".PHP_EOL;
+		self::assertEquals($e, $line);
+
+		$file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.1';
+		$this->checkFileContent($file);
+
+		$file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.2';
+		$this->checkFileContent($file);
+
+		// Should not roll over three times
+		$this->assertFalse(file_exists(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.3'));
+	}
+
+	public function testLoggingViaLogger() {
+		$logger = Logger::getLogger('mycat');
+		$logger->setAdditivity(false);
+
+		$appender = $this->createRolloverAppender();
+
+		$logger->addAppender($appender);
+
+		for($i = 0; $i < 1000; $i++) {
+			$logger->warn("my message123");
+		}
+
+		$logger->warn("my messageXYZ");
+
+		$file = PHPUNIT_TEMP_DIR.'/TEST-rolling.txt';
+		$data = file($file);
+
+		$line = $data[count($data)-1];
+		$e = "WARN - my messageXYZ".PHP_EOL;
+		self::assertEquals($e, $line);
+
+		$file = PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.1';
+		$this->checkFileContent($file);
+
+		$file = PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.2';
+		$this->checkFileContent($file);
+
+		$this->assertFalse(file_exists(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.3'), 'should not roll over three times');
+	}
+
+	public function testRolloverWithCompression() {
+		$logger = Logger::getLogger('mycat');
+		$logger->setAdditivity(false);
+
+		$appender = $this->createRolloverAppender();
+		$appender->setCompress(true);
+
+		$logger->addAppender($appender);
+
+		for($i = 0; $i < 1000; $i++) {
+			$logger->warn(self::WARNING_MASSAGE. $i);
+		}
+
+		$logger->warn("my messageXYZ");
+
+		$file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt';
+		$data = file($file);
+
+		$line = $data[count($data)-1];
+		$e = self::WARNING_MASSAGE.PHP_EOL;
+		self::assertEquals($e, $line);
+
+		$firstCompressedRollingFile = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.1.gz';
+		$this->assertTrue(file_exists($firstCompressedRollingFile),'TEST-rolling.txt.1.gz not found');
+
+		$firstUncompressedRollingField = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.1';
+		$this->assertFalse(file_exists($firstUncompressedRollingField),'TEST-rolling.txt.1 should be replaced by compressed');
+
+		$secondCompressedRollingFile = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.2.gz';
+		$this->assertTrue(file_exists($secondCompressedRollingFile), 'TEST-rolling.txt.2.gz not found');
+
+		$secondUncompressedRollingField = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.2';
+		$this->assertFalse(file_exists($secondUncompressedRollingField),'TEST-rolling.txt.2 should be replaced by compressed');
+
+	}
+
+	private function checkFileContent($file) {
+		$data = file($file);
+		$this->checkText($data);
+	}
+
+	private function checkText($text) {
+		$line = $text[count($text)-1];
+		$e = "WARN - my message123".PHP_EOL;
+		foreach($text as $r) {
+			self::assertEquals($e, $r);
+		}
+	}
+
+	protected function tearDown() {
+		@unlink(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt');
+		@unlink(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.1');
+		@unlink(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.2');
+		@unlink(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.1.gz');
+		@unlink(PHPUNIT_TEMP_DIR.'/TEST-rolling.txt.2.gz');
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/SocketAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/SocketAppenderTest.php b/tests/src/Appenders/SocketAppenderTest.php
new file mode 100644
index 0000000..9cd1482
--- /dev/null
+++ b/tests/src/Appenders/SocketAppenderTest.php
@@ -0,0 +1,151 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\SocketAppender;
+use Apache\Log4php\Logger;
+
+/**
+ * @group appenders
+ */
+class SocketAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	/** Port on which the socket server will run. */
+	const SOCKET_PORT = 12345;
+
+	/** The socket server process resource. */
+	private $server;
+
+	/** The pipes array for the server process. */
+	private $pipes;
+
+	public function setUp() {
+		Logger::clear();
+	}
+
+	public function tearDown() {
+		Logger::clear();
+	}
+
+	public function testRequiresLayout() {
+		$appender = new SocketAppender();
+		self::assertTrue($appender->requiresLayout());
+	}
+
+	public function testLogging()
+	{
+		Logger::configure(array(
+		    'appenders' => array(
+		        'default' => array(
+		            'class' => 'SocketAppender',
+		            'params' => array(
+		                'remoteHost' => 'localhost',
+		                'port' => self::SOCKET_PORT
+		            ),
+		            'layout' => array(
+		            	'class' => 'SimpleLayout'
+		            )
+		        ),
+		    ),
+		    'rootLogger' => array(
+		        'appenders' => array('default'),
+		    ),
+		));
+
+		$this->startServer();
+
+		$logger = Logger::getLogger("myLogger");
+		$logger->trace("This message is a test");
+		$logger->debug("This message is a test");
+		$logger->info("This message is a test");
+		$logger->warn("This message is a test");
+		$logger->error("This message is a test");
+		$logger->fatal("This message is a test");
+
+		$actual = $this->getPlayback();
+		$this->stopServer();
+
+		$expected = "DEBUG - This message is a test" .
+		            "INFO - This message is a test" .
+		            "WARN - This message is a test" .
+		            "ERROR - This message is a test" .
+		            "FATAL - This message is a test";
+
+		$this->assertEquals($expected, $actual);
+	}
+
+	/** Starts a socket server in a separate process. */
+	private function startServer() {
+		$serverLog = PHPUNIT_TEMP_DIR . '/socketServer.log';
+		$descriptorspec = array(
+			0 => array("pipe", "r"),  // stdin
+			1 => array("file", $serverLog, "a"),// stdout
+			2 => array("file", $serverLog, "a") // stderr
+		);
+
+		$cmd = "php " . dirname(__FILE__) . '/socketServer.php';
+		$this->server = proc_open($cmd, $descriptorspec, $this->pipes);
+		if ($this->server === false) {
+			throw new Exception("Failed starting the socket server process.");
+		}
+
+		// Sleep a bit to allow server to start
+		usleep(200000);
+
+		// Verify the server is running
+		$status = proc_get_status($this->server);
+		if (!$status['running']) {
+			throw new Exception("Socket server process failed to start. Check the log at [$serverLog].");
+		}
+	}
+
+	/** Sends a message to the socket server and returns the reply. */
+	private function socketSend($msg) {
+		$sock = fsockopen('localhost', self::SOCKET_PORT, $errno, $errstr);
+		if ($sock === false) {
+			throw new Exception("Unable to open socket. Error: [$errno] $errstr");
+		}
+
+		fputs($sock, "$msg\n");
+		$reply = '';
+		while(!feof($sock)) {
+			$reply .= fgets($sock);
+		}
+		fclose($sock);
+		return trim($reply);
+	}
+
+	/** Retrieves a playback of all sent messages from the socket server. */
+	private function getPlayback() {
+		return $this->socketSend('playback');
+	}
+
+	/** Stops the socket server and closes the process. */
+	private function stopServer() {
+		$this->socketSend('shutdown');
+		foreach($this->pipes as $pipe) {
+			fclose($pipe);
+		}
+		proc_close($this->server);
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/SyslogAppenderTest.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/SyslogAppenderTest.php b/tests/src/Appenders/SyslogAppenderTest.php
new file mode 100644
index 0000000..91b1568
--- /dev/null
+++ b/tests/src/Appenders/SyslogAppenderTest.php
@@ -0,0 +1,253 @@
+<?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\Appenders;
+
+use Apache\Log4php\Appenders\SyslogAppender;
+use Apache\Log4php\Layouts\SimpleLayout;
+use Apache\Log4php\Level;
+use Apache\Log4php\Logger;
+use Apache\Log4php\LoggingEvent;
+
+/**
+ * Tests the syslog appender.
+ *
+ * Many of these tests rely on reflection features introduced in 5.3 and
+ * will be skipped if run on a lower version.
+ *
+ * This test will only write a single entry to the syslog.
+ *
+ * @group appenders
+ */
+class SyslogAppenderTest extends \PHPUnit_Framework_TestCase {
+
+	public function testSettersGetters() {
+
+		// Setters should accept any value, without validation
+		$expected = "Random string value";
+
+		$appender = new SyslogAppender();
+		$appender->setIdent($expected);
+		$appender->setFacility($expected);
+		$appender->setOverridePriority($expected);
+		$appender->setPriority($expected);
+		$appender->setOption($expected);
+
+		$actuals = array(
+			$appender->getIdent(),
+			$appender->getFacility(),
+			$appender->getOverridePriority(),
+			$appender->getPriority(),
+			$appender->getOption()
+		);
+
+		foreach($actuals as $actual) {
+			$this->assertSame($expected, $actual);
+		}
+	}
+
+	public function testRequiresLayout() {
+		$appender = new SyslogAppender();
+		$this->assertTrue($appender->requiresLayout());
+	}
+
+	public function testLogging() {
+		$appender = new SyslogAppender("myname");
+		$appender->setLayout(new SimpleLayout());
+		$appender->activateOptions();
+
+		$event = new LoggingEvent(__CLASS__, new Logger("TestLogger"), Level::getLevelError(), "testmessage");
+		$appender->append($event);
+	}
+
+	/** Tests parsing of "option" parameter. */
+	public function testOption() {
+		$options = array(
+			'CONS' => LOG_CONS,
+			'NDELAY' => LOG_NDELAY,
+			'ODELAY' => LOG_ODELAY,
+			'PERROR' => LOG_PERROR,
+			'PID' => LOG_PID,
+
+			// test some combinations
+			'CONS|NDELAY' => LOG_CONS | LOG_NDELAY,
+			'PID|PERROR' => LOG_PID | LOG_PERROR,
+			'CONS|PID|NDELAY' => LOG_CONS | LOG_PID | LOG_NDELAY
+		);
+
+		// Defaults
+		$defaultStr = "PID|CONS";
+		$default = LOG_PID | LOG_CONS;
+
+		// This makes reading of a private property possible
+		$property = new \ReflectionProperty('Apache\\Log4php\Appenders\\SyslogAppender', 'intOption');
+		$property->setAccessible(true);
+
+		// Check default value first
+		$appender = new SyslogAppender();
+		$appender->activateOptions();
+		$actual = $property->getValue($appender);
+		$this->assertSame($default, $actual, "Failed setting default option [$defaultStr]");
+
+		foreach($options as $option => $expected) {
+			$appender = new SyslogAppender();
+			$appender->setOption($option);
+			$appender->activateOptions();
+
+			$actual = $property->getValue($appender);
+			$this->assertSame($expected, $actual, "Failed setting option [$option].");
+		}
+	}
+
+	/** Tests parsing of "priority" parameter. */
+	public function testPriority() {
+		$default = null;
+		$defaultStr = 'null';
+
+		$priorities = array(
+			'EMERG' => LOG_EMERG,
+			'ALERT' => LOG_ALERT,
+			'CRIT' => LOG_CRIT,
+			'ERR' => LOG_ERR,
+			'WARNING' => LOG_WARNING,
+			'NOTICE' => LOG_NOTICE,
+			'INFO' => LOG_INFO,
+			'DEBUG' => LOG_DEBUG
+		);
+
+		// This makes reading of a private property possible
+		$property = new \ReflectionProperty('Apache\\Log4php\\Appenders\\SyslogAppender', 'intPriority');
+		$property->setAccessible(true);
+
+		// Check default value first
+		$appender = new SyslogAppender();
+		$appender->activateOptions();
+		$actual = $property->getValue($appender);
+		$this->assertSame($default, $actual, "Failed setting default priority [$defaultStr].");
+
+		foreach($priorities as $priority => $expected) {
+			$appender = new SyslogAppender();
+			$appender->setPriority($priority);
+			$appender->activateOptions();
+
+			$actual = $property->getValue($appender);
+			$this->assertSame($expected, $actual, "Failed setting priority [$priority].");
+		}
+	}
+
+	/** Tests parsing of "facility" parameter. */
+	public function testFacility() {
+		// Default value is the same on all OSs
+		$default = LOG_USER;
+		$defaultStr = 'USER';
+
+		// All possible facility strings (some of which might not exist depending on the OS)
+		$strings = array(
+			'KERN', 'USER', 'MAIL', 'DAEMON', 'AUTH',
+			'SYSLOG', 'LPR', 'NEWS', 'UUCP', 'CRON', 'AUTHPRIV',
+			'LOCAL0', 'LOCAL1', 'LOCAL2', 'LOCAL3', 'LOCAL4',
+			'LOCAL5', 'LOCAL6', 'LOCAL7',
+		);
+
+		// Only test facilities which exist on this OS
+		$facilities = array();
+		foreach($strings as $string) {
+			$const = "LOG_$string";
+			if (defined($const)) {
+				$facilities[$string] = constant($const);
+			}
+		}
+
+		// This makes reading of a private property possible
+		$property = new \ReflectionProperty('Apache\\Log4php\\Appenders\\SyslogAppender', 'intFacility');
+		$property->setAccessible(true);
+
+		// Check default value first
+		$appender = new SyslogAppender();
+		$appender->activateOptions();
+		$actual = $property->getValue($appender);
+		$this->assertSame($default, $default, "Failed setting default facility [$defaultStr].");
+
+		foreach($facilities as $facility => $expected) {
+			$appender = new SyslogAppender();
+			$appender->setFacility($facility);
+			$appender->activateOptions();
+
+			$actual = $property->getValue($appender);
+			$this->assertSame($expected, $actual, "Failed setting priority [$facility].");
+		}
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 */
+	public function testInvalidOption() {
+		$appender = new SyslogAppender();
+		$appender->setOption('CONS|XYZ');
+		$appender->activateOptions();
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 */
+	public function testInvalidPriority() {
+		$appender = new SyslogAppender();
+		$appender->setPriority('XYZ');
+		$appender->activateOptions();
+	}
+
+	/**
+	 * @expectedException PHPUnit_Framework_Error
+	 */
+	public function testInvalidFacility() {
+		$appender = new SyslogAppender();
+		$appender->setFacility('XYZ');
+		$appender->activateOptions();
+	}
+
+
+	public function testPriorityOverride() {
+		$appender = new SyslogAppender();
+		$appender->setPriority('EMERG');
+		$appender->setOverridePriority(true);
+		$appender->activateOptions();
+
+		$levels = array(
+			Level::getLevelTrace(),
+			Level::getLevelDebug(),
+			Level::getLevelInfo(),
+			Level::getLevelWarn(),
+			Level::getLevelError(),
+			Level::getLevelFatal(),
+		);
+
+		$expected = LOG_EMERG;
+
+		$method = new \ReflectionMethod('Apache\\Log4php\\Appenders\\SyslogAppender', 'getSyslogPriority');
+		$method->setAccessible(true);
+
+		foreach($levels as $level) {
+			$actual = $method->invoke($appender, $level);
+			$this->assertSame($expected, $actual);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/79ed2d0d/tests/src/Appenders/socketServer.php
----------------------------------------------------------------------
diff --git a/tests/src/Appenders/socketServer.php b/tests/src/Appenders/socketServer.php
new file mode 100644
index 0000000..19a7b7c
--- /dev/null
+++ b/tests/src/Appenders/socketServer.php
@@ -0,0 +1,95 @@
+<?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
+ *
+ * A simple socket server used in LoggerAppenderSocketTest.
+ */
+
+// Port on which to start the server
+define('SERVER_PORT', 12345);
+
+// Prevent hangs
+set_time_limit(0);
+
+// Create a socket
+$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
+if ($sock === false) {
+	die("Failed creating socket: " . socket_strerror(socket_last_error()));
+}
+
+if (socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1) === false) {
+	die("Failed setting socket options: " . socket_strerror(socket_last_error()));
+}
+
+if (socket_bind($sock, 'localhost', SERVER_PORT) === false) {
+	die("Failed binding socket: " . socket_strerror(socket_last_error()));
+}
+
+if (socket_listen($sock, 100) === false) {
+	die("Failed binding socket: " . socket_strerror(socket_last_error()));
+}
+
+socket_getsockname($sock, $addr, $port);
+myLog("Server Listening on $addr:$port");
+
+// Buffer which will store incoming messages
+$playback = "";
+
+while(true) {
+	myLog("Waiting for incoming connections...");
+
+	$msgsock = socket_accept($sock);
+	if ($msgsock === false) {
+		myLog("Failed accepting a connection: " . socket_strerror(socket_last_error()));
+		break;
+	}
+
+	$buf = socket_read($msgsock, 2048, PHP_NORMAL_READ);
+
+	myLog('Received: "' . trim($buf) . '"');
+
+	// Shutdown command
+	if (trim($buf) == 'shutdown') {
+		myLog("Shutting down.");
+		socket_close($msgsock);
+		break;
+	}
+	// Playback command
+	else if (trim($buf) == 'playback') {
+		myLog("Returning playback: \"$playback\"");
+		socket_write($msgsock, $playback);
+	}
+	// Default: add to playback buffer
+	else {
+		$playback .= trim($buf);
+	}
+
+	socket_close($msgsock);
+}
+
+myLog("Closing socket.");
+socket_close($sock);
+
+function myLog($msg) {
+	echo date("Y-m-d H:i:s") . " $msg\n";
+}
+
+?>


Mime
View raw message