logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1237433 - in /logging/log4php/trunk/src: main/php/appenders/LoggerAppenderMailEvent.php test/php/appenders/LoggerAppenderMailEventTest.php
Date Sun, 29 Jan 2012 19:43:23 GMT
Author: ihabunek
Date: Sun Jan 29 19:43:22 2012
New Revision: 1237433

URL: http://svn.apache.org/viewvc?rev=1237433&view=rev
Log:
Improved error reporting for mail event appender. Removed thrown exceptions.

Modified:
    logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php
    logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php

Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php?rev=1237433&r1=1237432&r2=1237433&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php Sun Jan 29 19:43:22
2012
@@ -82,16 +82,17 @@ class LoggerAppenderMailEvent extends Lo
 	protected $dry = false;
 	
 	public function activateOptions() {
-		if (empty($this->layout)) {
-			throw new LoggerException("LoggerAppenderMailEvent requires layout!");
-		}
 		if (empty($this->to)) {
-			throw new LoggerException("LoggerAppenderMailEvent was initialized with empty 'from' ($this->from)
or 'to' ($this->to) Adress!");
+			$this->warn("Required parameter 'to' not set. Closing appender.");
+			$this->close = true;
+			return;
 		}
 		
 		$sendmail_from = ini_get('sendmail_from');
 		if (empty($this->from) and empty($sendmail_from)) {
-			throw new LoggerException("LoggerAppenderMailEvent requires 'from' or on win32 at least
the ini variable sendmail_from!");
+			$this->warn("Required parameter 'from' not set. Closing appender.");
+			$this->close = true;
+			return;
 		}
 		
 		$this->closed = false;

Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php?rev=1237433&r1=1237432&r2=1237433&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php Sun Jan 29
19:43:22 2012
@@ -27,7 +27,7 @@
  * @group appenders
  */
 class LoggerAppenderMailEventTest extends PHPUnit_Framework_TestCase {
-        
+	
 	public function testRequiresLayout() {
 		$appender = new LoggerAppenderMailEvent();
 		self::assertTrue($appender->requiresLayout());
@@ -53,16 +53,29 @@ class LoggerAppenderMailEventTest extend
 		$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 if invalid configurations are rejected. 
-     * @expectedException LoggerException with empty
-     */
-    public function testEmptyTo() {
-        $appender = new LoggerAppenderMailEvent("myname");
-        $appender->setLayout(new LoggerLayoutSimple());
-        $appender->setFrom('info@example.com');
-        $appender->activateOptions();
-    }
+	/** 
+	 * 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 LoggerAppenderMailEvent("myname");
+		$appender->setLayout(new LoggerLayoutSimple());
+		$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 LoggerAppenderMailEvent("myname");
+		$appender->setLayout(new LoggerLayoutSimple());
+		$appender->setTo('info@example.com');
+		$appender->activateOptions();
+	}
 }



Mime
View raw message