Changeset 1091

Show
Ignore:
Timestamp:
11/29/07 23:20:41 (7 months ago)
Author:
mikey
Message:

added unit test for net::stubbles::util::errorhandler::stubAbstractExceptionHandler

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/util/errorhandler/stubAbstractExceptionHandler.php

    r1089 r1091  
    2525     */ 
    2626    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; 
    2739 
    2840    /** 
     
    3446    { 
    3547        $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; 
    3668    } 
    3769 
     
    70102    { 
    71103        stubClassLoader::load('net.stubbles.util.log.log'); 
    72         $logData = stubLogDataFactory::create('exceptions', stubLogger::LEVEL_ERROR); 
     104        $logData = stubLogDataFactory::create($this->logTarget, $this->logLevel); 
    73105        $logData->addData(($exception instanceof stubThrowable) ? ($exception->getClassName()) : (get_class($exception))); 
    74106        $logData->addData($exception->getMessage()); 
  • trunk/src/test/php/net/stubbles/util/UtilTestSuite.php

    r1088 r1091  
    4040 
    4141        // error handler 
     42        $this->addTestFile($dir . '/errorhandler/stubAbstractExceptionHandlerTestCase.php'); 
    4243        $this->addTestFile($dir . '/errorhandler/stubCompositeErrorHandlerTestCase.php'); 
    4344        $this->addTestFile($dir . '/errorhandler/stubIllegalArgumentErrorHandlerTestCase.php'); 
  • trunk/src/test/php/net/stubbles/util/errorhandler/stubLogErrorHandlerTestCase.php

    r1088 r1091  
    77 * @subpackage  util_errorhandler_test 
    88 */ 
    9 stubClassLoader::load('net.stubbles.util.errorhandler.stubLogErrorHandler'); 
     9stubClassLoader::load('net.stubbles.util.errorhandler.stubLogErrorHandler', 
     10                      'net.stubbles.util.log.stubMemoryLogAppender' 
     11); 
    1012Mock::generate('stubSession'); 
    11 /** 
    12  * Mocked log appender to get access to the logged logdata object. 
    13  * 
    14  * @package     stubbles 
    15  * @subpackage  util_errorhandler_test 
    16  */ 
    17 class stubTestLogAppender extends stubBaseObject implements stubLogAppender 
    18 { 
    19     /** 
    20      * collected logdata objects 
    21      * 
    22      * @var  array<stubLogData> 
    23      */ 
    24     protected $logData = array(); 
    2513 
    26     /** 
    27      * sets the configuration data 
    28      * 
    29      * @param  array  $config 
    30      */ 
    31     public function setConfig(array $config) { } 
    32  
    33     /** 
    34      * returns the configuration 
    35      * 
    36      * @return  array 
    37      */ 
    38     public function getConfig() 
    39     { 
    40         return array(); 
    41     } 
    42  
    43     /** 
    44      * append the log data to the log target 
    45      * 
    46      * @param  stubLogData  $logData 
    47      */ 
    48     public function append(stubLogData $logData) 
    49     { 
    50         $this->logData[] = $logData; 
    51     } 
    52  
    53     /** 
    54      * returns collected logdata objects 
    55      * 
    56      * @return  array<stubLogData> 
    57      */ 
    58     public function getLogData() 
    59     { 
    60         return $this->logData; 
    61     } 
    62  
    63     /** 
    64      * finalize the log target 
    65      */ 
    66     public function finalize() {} 
    67 } 
    6814/** 
    6915 * Tests for net::stubbles::util::errorhandler::stubLogErrorHandler. 
     
    12268 
    12369    /** 
    124      * assure that the error is logged if the session is set 
     70     * assure that the error is logged 
    12571     */ 
    12672    public function testHandle() 
    12773    { 
    12874        $logger      = stubLogger::getInstance(__CLASS__); 
    129         $logAppender = new stubTestLogAppender(); 
     75        $logAppender = new stubMemoryLogAppender(); 
    13076        $logger->addLogAppender($logAppender); 
    13177        $this->logErrorHandler->handle(E_USER_ERROR, 'foo', 'bar', 9, array('blub' => 'baz')); 
    13278        $logData = $logAppender->getLogData(); 
    13379        $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()); 
    13784        $this->assertEqual($logDataContents[1], E_USER_ERROR); 
    13885        $this->assertEqual($logDataContents[2], 'E_USER_ERROR');