Changeset 360

Show
Ignore:
Timestamp:
03/10/07 00:34:01 (2 years ago)
Author:
mikey
Message:

use more unique keys
removed tabs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubFloatFilter.php

    r152 r360  
    3131     * @param  stubValidator                 $max         validator for maximum values 
    3232     */ 
    33    public function __construct(stubRequestValueErrorFactory $rveFactory, stubValidator $min = null, stubValidator $max = null) 
    34    
    35        parent::__construct($rveFactory, $min, $max); 
    36    
     33    public function __construct(stubRequestValueErrorFactory $rveFactory, stubValidator $min = null, stubValidator $max = null) 
     34   
     35        parent::__construct($rveFactory, $min, $max); 
     36   
    3737 
    3838    /** 
     
    4343     * @throws  stubFilterException  in case $value has errors 
    4444     */ 
    45    function execute($value) 
    46    
    47        if ((strlen($value) > 0 && true == $this->isRequired) || false == $this->isRequired || false === $value) { 
     45    function execute($value) 
     46   
     47        if ((strlen($value) > 0 && true == $this->isRequired) || false == $this->isRequired || false === $value) { 
    4848            settype($value, 'float'); 
    49        } 
    50             
     49        } 
     50         
    5151        $value = parent::doExecute($value); 
    52         return (int) ($value * pow(10, stubRegistry::getConfig('core.number.decimals'))); 
    53    
     52        return (int) ($value * pow(10, stubRegistry::getConfig('net.stubbles.number.decimals'))); 
     53   
    5454} 
    5555?> 
  • trunk/src/main/php/net/stubbles/util/stubExceptionHandler.php

    r326 r360  
    3434    public static function handle(Exception $exception) 
    3535    { 
    36         if (stubRegistry::hasConfig('mode') == true && stubRegistry::getConfig('mode') == 'test') { 
     36        if (stubRegistry::hasConfig('net.stubbles.mode') == true && stubRegistry::getConfig('net.stubbles.mode') == 'test') { 
    3737            $response = new stubBaseResponse(); 
    3838            if ($exception instanceof stubException) { 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubFloatFilterTestCase.php

    r140 r360  
    11<?php 
    22/** 
    3  * Tests for ipo.request.filters.stubDoubleFilter 
     3 * Tests for net.stubbles.ipo.request.filters.stubDoubleFilter 
    44 * 
    55 * @author      Frank Kleine <frank@kl-s.com> 
    66 * @package     stubbles 
    7  * @subpackage  ipo_test 
     7 * @subpackage  ipo_request_filters_test 
    88 */ 
    99stubClassLoader::load('net.stubbles.ipo.request.filters.stubFloatFilter'); 
     
    1111Mock::generate('stubValidator'); 
    1212/** 
    13  * Tests for ipo.request.filters.stubDoubleFilter 
     13 * Tests for net.stubbles.ipo.request.filters.stubDoubleFilter 
    1414 * 
    1515 * @package     stubbles 
    16  * @subpackage  ipo_test 
     16 * @subpackage  ipo_request_filters_test 
    1717 */ 
    1818class stubFloatFilterTestCase extends UnitTestCase 
     
    4040     * set up test environment 
    4141     */ 
    42    public function setUp() 
    43    
    44        stubRegistry::setConfig('core.number.decimals', 3); 
    45        $this->mockStubRequestValueErrorFactory = new MockStubRequestValueErrorFactory(); 
     42    public function setUp() 
     43   
     44        stubRegistry::setConfig('net.stubbles.number.decimals', 3); 
     45        $this->mockStubRequestValueErrorFactory = new MockStubRequestValueErrorFactory(); 
    4646        $this->mockStubValidatorMin             = new MockStubValidator(); 
    4747        $this->mockStubValidatorMax             = new MockStubValidator(); 
    4848        $this->mockStubRequestValueErrorFactory->setReturnValue('create', new stubRequestValueError('foo', array('en_EN' => 'Something wrent wrong.'))); 
    49    
     49   
    5050 
    5151    /** 
    5252     * assure that values are returned the expected way 
    5353     */ 
    54    public function testValue() 
    55    
    56        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
    57        $this->assertEqual($floatFilter->execute('8.4533'), 8453); 
    58        $this->assertEqual($floatFilter->execute('8.4538'), 8453); 
    59        $this->assertEqual($floatFilter->execute('8.45'), 8450); 
    60        $this->assertEqual($floatFilter->execute('8'), 8000); 
    61        $this->assertEqual($floatFilter->execute(8.4533), 8453); 
    62        $this->assertEqual($floatFilter->execute(8.4538), 8453); 
    63        $this->assertEqual($floatFilter->execute(8.45), 8450); 
    64        $this->assertEqual($floatFilter->execute(8), 8000); 
    65    
     54    public function testValue() 
     55   
     56        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
     57        $this->assertEqual($floatFilter->execute('8.4533'), 8453); 
     58        $this->assertEqual($floatFilter->execute('8.4538'), 8453); 
     59        $this->assertEqual($floatFilter->execute('8.45'), 8450); 
     60        $this->assertEqual($floatFilter->execute('8'), 8000); 
     61        $this->assertEqual($floatFilter->execute(8.4533), 8453); 
     62        $this->assertEqual($floatFilter->execute(8.4538), 8453); 
     63        $this->assertEqual($floatFilter->execute(8.45), 8450); 
     64        $this->assertEqual($floatFilter->execute(8), 8000); 
     65   
    6666 
    6767    /** 
     
    6969     * required but not passed 
    7070     */ 
    71    public function testWithUnsetWhenRequired() 
    72    
    73        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
    74        $floatFilter->setRequired(true); 
    75        $this->assertEqual($floatFilter->execute(true), 1000); 
    76        $this->assertEqual($floatFilter->execute(false), 0); 
    77        $this->expectException('stubFilterException'); 
    78        $floatFilter->execute(null); 
    79    
    80      
    81    /** 
     71    public function testWithUnsetWhenRequired() 
     72   
     73        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
     74        $floatFilter->setRequired(true); 
     75        $this->assertEqual($floatFilter->execute(true), 1000); 
     76        $this->assertEqual($floatFilter->execute(false), 0); 
     77        $this->expectException('stubFilterException'); 
     78        $floatFilter->execute(null); 
     79   
     80 
     81    /** 
    8282     * assure that an exceptiom is thrown when a value is 
    8383     * required but not passed 
    8484     */ 
    85    public function testWithUnsetEmptyStringWhenRequired() 
    86    
    87        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
    88        $floatFilter->setRequired(true); 
    89        $this->expectException('stubFilterException'); 
    90        $floatFilter->execute(''); 
    91    
     85    public function testWithUnsetEmptyStringWhenRequired() 
     86   
     87        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
     88        $floatFilter->setRequired(true); 
     89        $this->expectException('stubFilterException'); 
     90        $floatFilter->execute(''); 
     91   
    9292 
    9393    /** 
     
    9595     * is required 
    9696     */ 
    97    public function testUnsetWhenNotRequired() 
    98    
    99        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
    100        $floatFilter->setRequired(false); 
    101        $this->assertEqual($floatFilter->execute(null), 0); 
    102        $this->assertEqual($floatFilter->execute(''), 0); 
    103        $this->assertEqual($floatFilter->execute(true), 1000); 
    104        $this->assertEqual($floatFilter->execute(false), 0); 
    105    
     97    public function testUnsetWhenNotRequired() 
     98   
     99        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
     100        $floatFilter->setRequired(false); 
     101        $this->assertEqual($floatFilter->execute(null), 0); 
     102        $this->assertEqual($floatFilter->execute(''), 0); 
     103        $this->assertEqual($floatFilter->execute(true), 1000); 
     104        $this->assertEqual($floatFilter->execute(false), 0); 
     105   
    106106 
    107107    /** 
    108108     * assure that an FilterException is thrown when value smaller then $min 
    109109     */ 
    110    public function testWithMinValidator() 
    111    
    112        $this->mockStubValidatorMin->setReturnValueAt(0, 'validate', true); 
    113        $this->mockStubValidatorMin->setReturnValueAt(1, 'validate', false); 
    114        $this->mockStubValidatorMin->setReturnValue('getCriteria', array()); 
    115         
    116        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, $this->mockStubValidatorMin); 
    117        $this->assertEqual($floatFilter->execute(-10), -10000); 
    118        $this->expectException('stubFilterException'); 
    119        $floatFilter->execute(-11); 
    120    
     110    public function testWithMinValidator() 
     111   
     112        $this->mockStubValidatorMin->setReturnValueAt(0, 'validate', true); 
     113        $this->mockStubValidatorMin->setReturnValueAt(1, 'validate', false); 
     114        $this->mockStubValidatorMin->setReturnValue('getCriteria', array()); 
     115         
     116        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, $this->mockStubValidatorMin); 
     117        $this->assertEqual($floatFilter->execute(-10), -10000); 
     118        $this->expectException('stubFilterException'); 
     119        $floatFilter->execute(-11); 
     120   
    121121 
    122122    /** 
    123123     * assure that an FilterException is thrown when value greater then $max 
    124124     */ 
    125    public function testWithMaxValidator() 
    126    
    127        $this->mockStubValidatorMax->setReturnValueAt(0, 'validate', true); 
    128        $this->mockStubValidatorMax->setReturnValueAt(1, 'validate', false); 
    129        $this->mockStubValidatorMax->setReturnValue('getCriteria', array()); 
    130         
    131        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, null, $this->mockStubValidatorMax); 
    132        $this->assertEqual($floatFilter->execute(10), 10000); 
    133        $this->expectException('stubFilterException'); 
    134        $floatFilter->execute(11); 
    135    
     125    public function testWithMaxValidator() 
     126   
     127        $this->mockStubValidatorMax->setReturnValueAt(0, 'validate', true); 
     128        $this->mockStubValidatorMax->setReturnValueAt(1, 'validate', false); 
     129        $this->mockStubValidatorMax->setReturnValue('getCriteria', array()); 
     130         
     131        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory, null, $this->mockStubValidatorMax); 
     132        $this->assertEqual($floatFilter->execute(10), 10000); 
     133        $this->expectException('stubFilterException'); 
     134        $floatFilter->execute(11); 
     135   
    136136    /** 
    137137     * assure that the correct value depending on $decimal_places is returned 
    138138     */ 
    139    public function testFloat() 
    140    
    141        stubRegistry::setConfig('core.number.decimals', 2); 
    142        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
    143        $this->assertEqual($floatFilter->execute('1.564'), 156); 
    144    
     139    public function testFloat() 
     140   
     141        stubRegistry::setConfig('net.stubbles.number.decimals', 2); 
     142        $floatFilter = new stubFloatFilter($this->mockStubRequestValueErrorFactory); 
     143        $this->assertEqual($floatFilter->execute('1.564'), 156); 
     144   
    145145} 
    146146?>