Development

Changeset 10802

You must first sign up to be able to contribute.

Changeset 10802

Show
Ignore:
Timestamp:
08/12/08 09:10:53 (6 years ago)
Author:
fabien
Message:

[1.1, 1.2] added an exception when using a non existant operator with sfValidatorSchemaCompare

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/validator/sfValidatorSchemaCompare.class.php

    r9048 r10802  
    9797        break; 
    9898      case self::EQUAL: 
     99        $valid = $leftValue == $rightValue; 
     100        break; 
    99101      default: 
    100         $valid = $leftValue == $rightValue
     102        throw new InvalidArgumentException(sprintf('The operator "%s" does not exist.', $this->getOption('operator')))
    101103    } 
    102104 
  • branches/1.1/test/unit/validator/sfValidatorSchemaCompareTest.php

    r6954 r10802  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(43, new lime_output_color()); 
     13$t = new lime_test(44, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
     
    7272} 
    7373 
     74$v = new sfValidatorSchemaCompare('left', '==', 'right'); 
     75try 
     76{ 
     77  $v->clean(array()); 
     78  $t->fail('->clean() throws an InvalidArgumentException exception if the operator does not exist'); 
     79} 
     80catch (InvalidArgumentException $e) 
     81{ 
     82  $t->pass('->clean() throws an InvalidArgumentException exception if the operator does not exist'); 
     83} 
     84 
    7485// ->asString() 
    7586$t->diag('->asString()'); 
    76 $v = new sfValidatorSchemaCompare('left', '==', 'right'); 
    77 $t->is($v->asString(), 'left == right', '->asString() returns a string representation of the validator'); 
     87$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
     88$t->is($v->asString(), 'left equal right', '->asString() returns a string representation of the validator'); 
    7889 
    79 $v = new sfValidatorSchemaCompare('left', '==', 'right', array(), array('required' => 'This is required.')); 
    80 $t->is($v->asString(), 'left ==({}, { required: \'This is required.\' }) right', '->asString() returns a string representation of the validator'); 
     90$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right', array(), array('required' => 'This is required.')); 
     91$t->is($v->asString(), 'left equal({}, { required: \'This is required.\' }) right', '->asString() returns a string representation of the validator'); 
  • branches/1.2/lib/validator/sfValidatorSchemaCompare.class.php

    r10800 r10802  
    9797        break; 
    9898      case self::EQUAL: 
     99        $valid = $leftValue == $rightValue; 
     100        break; 
    99101      default: 
    100         $valid = $leftValue == $rightValue
     102        throw new InvalidArgumentException(sprintf('The operator "%s" does not exist.', $this->getOption('operator')))
    101103    } 
    102104 
  • branches/1.2/test/unit/validator/sfValidatorSchemaCompareTest.php

    r10800 r10802  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(83, new lime_output_color()); 
     13$t = new lime_test(84, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
     
    9090} 
    9191 
     92$v = new sfValidatorSchemaCompare('left', 'foo', 'right'); 
     93try 
     94{ 
     95  $v->clean(array()); 
     96  $t->fail('->clean() throws an InvalidArgumentException exception if the operator does not exist'); 
     97} 
     98catch (InvalidArgumentException $e) 
     99{ 
     100  $t->pass('->clean() throws an InvalidArgumentException exception if the operator does not exist'); 
     101} 
     102 
    92103// ->asString() 
    93104$t->diag('->asString()'); 
    94 $v = new sfValidatorSchemaCompare('left', '==', 'right'); 
     105$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
    95106$t->is($v->asString(), 'left == right', '->asString() returns a string representation of the validator'); 
    96107 
    97 $v = new sfValidatorSchemaCompare('left', '==', 'right', array(), array('required' => 'This is required.')); 
     108$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right', array(), array('required' => 'This is required.')); 
    98109$t->is($v->asString(), 'left ==({}, { required: \'This is required.\' }) right', '->asString() returns a string representation of the validator');