Changeset 1091
- Timestamp:
- 11/29/07 23:20:41 (7 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/util/errorhandler/stubAbstractExceptionHandler.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/util/UtilTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/util/errorhandler/stubAbstractExceptionHandlerTestCase.php (added)
- trunk/src/test/php/net/stubbles/util/errorhandler/stubLogErrorHandlerTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/util/errorhandler/stubAbstractExceptionHandler.php
r1089 r1091 25 25 */ 26 26 protected $loggingEnabled = true; 27 /** 28 * target of the log data 29 * 30 * @var string 31 */ 32 protected $logTarget = 'exceptions'; 33 /** 34 * the error level to use for the log data 35 * 36 * @var int 37 */ 38 protected $logLevel = stubLogger::LEVEL_ERROR; 27 39 28 40 /** … … 34 46 { 35 47 $this->loggingEnabled = $loggingEnabled; 48 } 49 50 /** 51 * sets the target of the log data 52 * 53 * @param string $logName 54 */ 55 public function setLogTarget($logTarget) 56 { 57 $this->logTarget = $logTarget; 58 } 59 60 /** 61 * sets the level of the log data 62 * 63 * @param int $logLevel 64 */ 65 public function setLogLevel($logLevel) 66 { 67 $this->logLevel = $logLevel; 36 68 } 37 69 … … 70 102 { 71 103 stubClassLoader::load('net.stubbles.util.log.log'); 72 $logData = stubLogDataFactory::create( 'exceptions', stubLogger::LEVEL_ERROR);104 $logData = stubLogDataFactory::create($this->logTarget, $this->logLevel); 73 105 $logData->addData(($exception instanceof stubThrowable) ? ($exception->getClassName()) : (get_class($exception))); 74 106 $logData->addData($exception->getMessage()); trunk/src/test/php/net/stubbles/util/UtilTestSuite.php
r1088 r1091 40 40 41 41 // error handler 42 $this->addTestFile($dir . '/errorhandler/stubAbstractExceptionHandlerTestCase.php'); 42 43 $this->addTestFile($dir . '/errorhandler/stubCompositeErrorHandlerTestCase.php'); 43 44 $this->addTestFile($dir . '/errorhandler/stubIllegalArgumentErrorHandlerTestCase.php'); trunk/src/test/php/net/stubbles/util/errorhandler/stubLogErrorHandlerTestCase.php
r1088 r1091 7 7 * @subpackage util_errorhandler_test 8 8 */ 9 stubClassLoader::load('net.stubbles.util.errorhandler.stubLogErrorHandler'); 9 stubClassLoader::load('net.stubbles.util.errorhandler.stubLogErrorHandler', 10 'net.stubbles.util.log.stubMemoryLogAppender' 11 ); 10 12 Mock::generate('stubSession'); 11 /**12 * Mocked log appender to get access to the logged logdata object.13 *14 * @package stubbles15 * @subpackage util_errorhandler_test16 */17 class stubTestLogAppender extends stubBaseObject implements stubLogAppender18 {19 /**20 * collected logdata objects21 *22 * @var array<stubLogData>23 */24 protected $logData = array();25 13 26 /**27 * sets the configuration data28 *29 * @param array $config30 */31 public function setConfig(array $config) { }32 33 /**34 * returns the configuration35 *36 * @return array37 */38 public function getConfig()39 {40 return array();41 }42 43 /**44 * append the log data to the log target45 *46 * @param stubLogData $logData47 */48 public function append(stubLogData $logData)49 {50 $this->logData[] = $logData;51 }52 53 /**54 * returns collected logdata objects55 *56 * @return array<stubLogData>57 */58 public function getLogData()59 {60 return $this->logData;61 }62 63 /**64 * finalize the log target65 */66 public function finalize() {}67 }68 14 /** 69 15 * Tests for net::stubbles::util::errorhandler::stubLogErrorHandler. … … 122 68 123 69 /** 124 * assure that the error is logged if the session is set70 * assure that the error is logged 125 71 */ 126 72 public function testHandle() 127 73 { 128 74 $logger = stubLogger::getInstance(__CLASS__); 129 $logAppender = new stub TestLogAppender();75 $logAppender = new stubMemoryLogAppender(); 130 76 $logger->addLogAppender($logAppender); 131 77 $this->logErrorHandler->handle(E_USER_ERROR, 'foo', 'bar', 9, array('blub' => 'baz')); 132 78 $logData = $logAppender->getLogData(); 133 79 $this->assertEqual(count($logData), 1); 134 $this->assertEqual($logData[0]->getTarget(), 'php-error'); 135 $this->assertEqual($logData[0]->getLevel(), stubLogger::LEVEL_ERROR); 136 $logDataContents = explode(stubLogData::SEPERATOR, $logData[0]->get()); 80 $this->assertEqual(count($logData['php-error']), 1); 81 $this->assertEqual($logData['php-error'][0]->getTarget(), 'php-error'); 82 $this->assertEqual($logData['php-error'][0]->getLevel(), stubLogger::LEVEL_ERROR); 83 $logDataContents = explode(stubLogData::SEPERATOR, $logData['php-error'][0]->get()); 137 84 $this->assertEqual($logDataContents[1], E_USER_ERROR); 138 85 $this->assertEqual($logDataContents[2], 'E_USER_ERROR');
