Changeset 1084

Show
Ignore:
Timestamp:
11/29/07 00:25:05 (9 months ago)
Author:
mikey
Message:

made net::stubbles::util::log::stubBaseLogData independent of session (first steps for enhancement #112)

Files:

Legend:

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

    r816 r1084  
    88 */ 
    99stubClassLoader::load('net.stubbles.util.log.stubLogData', 
    10                       'net.stubbles.util.log.stubLogger', 
    11                       'net.stubbles.ipo.session.stubSession' 
     10                      'net.stubbles.util.log.stubLogger' 
    1211); 
    1312/** 
     
    5352     * log appender will not mess up the log data. 
    5453     * 
    55      * @param  stubSession  $session  the session of the current user 
    56      * @param  string       $target   target where the log data should go to 
    57      * @param  int          $level    optional  log level of the log data 
     54     * @param  string  $target     target where the log data should go to 
     55     * @param  int     $level      optional  log level of the log data 
     56     * @param  string  $sessionId  optional  session id of current user 
    5857     */ 
    59     public function __construct(stubSession $session, $target, $level = stubLogger::LEVEL_INFO
     58    public function __construct($target, $level = stubLogger::LEVEL_INFO, $sessionId = null
    6059    { 
    6160        $this->target  = $target; 
    6261        $this->level   = $level; 
    6362        $this->logData = array(date('Y-m-d H:i:s'), 
    64                                $session->getId() 
     63                               (string) $sessionId 
    6564                         ); 
    6665    } 
  • trunk/src/main/php/net/stubbles/util/log/stubLogDataFactory.php

    r887 r1084  
    3333        $fqClassName = stubRegistry::getConfig('net.stubbles.util.log.class', 'net.stubbles.util.log.stubBaseLogData'); 
    3434        $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName); 
    35         if (class_exists($nqClassName, false) == false) { 
     35        if (class_exists($nqClassName, false) === false) { 
    3636            stubClassLoader::load($fqClassName); 
    3737        } 
    3838         
    39         $logData = new $nqClassName($session, $target, $level); 
    40         if (($logData instanceof stubLogData) == false) { 
     39        $logData = new $nqClassName($target, $level, $session->getId()); 
     40        if (($logData instanceof stubLogData) === false) { 
    4141            throw new stubRuntimeException('Configured net.stubbles.util.log.class is not an instance of stubLogData.'); 
    4242        } 
  • trunk/src/test/php/net/stubbles/util/log/stubBaseLogDataTestCase.php

    r146 r1084  
    11<?php 
    22/** 
    3  * Test for net.stubbles.util.log.stubBaseLogData. 
     3 * Test for net::stubbles::util::log::stubBaseLogData. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    88 */ 
    99stubClassLoader::load('net.stubbles.util.log.stubBaseLogData'); 
    10 Mock::generate('stubSession'); 
    1110/** 
    12  * Test for net.stubbles.util.log.stubBaseLogData. 
     11 * Test for net::stubbles::util::log::stubBaseLogData. 
    1312 * 
    1413 * @package     stubbles 
     
    1817{ 
    1918    /** 
    20      * instance to test 
    21      * 
    22      * @var  stubBaseLogData 
     19     * assure that data is handles as expected 
    2320     */ 
    24     protected $baseLogData; 
    25      
    26     /** 
    27      * set up the test environment 
    28      */ 
    29     public function setUp() 
     21    public function testWithSessionId() 
    3022    { 
    31         $mockSession = new MockstubSession(); 
    32         $mockSession->setReturnValue('getId', 'foo'); 
    33         $this->baseLogData = new stubBaseLogData($mockSession, 'bar'); 
     23        $baseLogData = new stubBaseLogData('bar', stubLogger::LEVEL_INFO, 'foo'); 
     24        $this->assertEqual($baseLogData->getLevel(), stubLogger::LEVEL_INFO); 
     25        $this->assertEqual($baseLogData->getTarget(), 'bar'); 
     26        $baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 
     27        $data = explode(stubLogData::SEPERATOR, $baseLogData->get()); 
     28        $this->assertEqual($data[1], 'foo'); 
     29        $this->assertEqual($data[2], 'ba<nl>zvvv'); 
    3430    } 
    35      
     31 
    3632    /** 
    3733     * assure that data is handles as expected 
    3834     */ 
    39     public function testData() 
     35    public function testWithoutSessionId() 
    4036    { 
    41         $this->assertEqual($this->baseLogData->getLevel(), stubLogger::LEVEL_INFO); 
    42         $this->assertEqual($this->baseLogData->getTarget(), 'bar'); 
    43         $this->baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 
    44         $data = explode(stubLogData::SEPERATOR, $this->baseLogData->get()); 
    45         $this->assertEqual($data[1], 'foo'); 
     37        $baseLogData = new stubBaseLogData('bar'); 
     38        $this->assertEqual($baseLogData->getLevel(), stubLogger::LEVEL_INFO); 
     39        $this->assertEqual($baseLogData->getTarget(), 'bar'); 
     40        $baseLogData->addData("ba\r\nz" . stubLogData::SEPERATOR . 'vvv'); 
     41        $data = explode(stubLogData::SEPERATOR, $baseLogData->get()); 
     42        $this->assertEqual($data[1], ''); 
    4643        $this->assertEqual($data[2], 'ba<nl>zvvv'); 
    4744    }