public static function advancedValidator($validator, $values)
 {
     if ($values['form_type'] === 'input' || $values['form_type'] === 'textarea') {
         $validator = new sfValidatorInteger(array('required' => false));
         $values['value_min'] = $validator->clean($values['value_min']);
         $values['value_max'] = $validator->clean($values['value_max']);
     } elseif ($values['form_type'] === 'date') {
         $validator = new opValidatorDate(array('required' => false));
         $validator->clean($values['value_min']);
         $validator->clean($values['value_max']);
     } elseif ($values['value_min'] || $values['value_max']) {
         throw new sfValidatorError($validator, 'invalid');
     }
     return $values;
 }
 protected function checkRange($range = array())
 {
     // checking single values
     if (isset($range['date_from'])) {
         $v = new sfValidatorDate();
         $range['date_from'] = $v->clean($range['date_from']);
     }
     if (isset($range['date_to'])) {
         $v = new sfValidatorDate();
         $range['date_to'] = $v->clean($range['date_to']);
     }
     if (isset($range['kilometers_from'])) {
         $v = new sfValidatorInteger(array('min' => 0));
         $range['kilometers_from'] = $v->clean($range['kilometers_from']);
     }
     if (isset($range['kilometers_to'])) {
         $v = new sfValidatorInteger(array('min' => 0));
         $range['kilometers_to'] = $v->clean($range['kilometers_to']);
     }
     // checking ranges
     if (isset($range['date_from']) && isset($range['kilometers_from'])) {
         throw new sfException('Only one between "date_from" and "kilometers_from" can be set.');
     }
     if (isset($range['date_to']) && isset($range['kilometers_to'])) {
         throw new sfException('Only one between "date_to" and "kilometers_to" can be set.');
     }
     $this->log('Range: ');
     if (isset($range['date_from'])) {
         $this->log('  - From ' . $range['date_from']);
     }
     if (isset($range['kilometers_from'])) {
         $this->log('  - From ' . $range['kilometers_from'] . ' km');
     }
     if (isset($range['date_to'])) {
         $this->log('  - To ' . $range['date_to']);
     }
     if (isset($range['kilometers_to'])) {
         $this->log('  - To ' . $range['kilometers_to'] . ' km');
     }
     if (!isset($range['date_from']) && !isset($range['kilometers_from'])) {
         $range['kilometers_from'] = 0;
         $this->log('  - From 0 km');
     }
     if (!isset($range['date_to']) && !isset($range['kilometers_to'])) {
         $range['date_to'] = date('Y-m-d');
         $this->log('  - To ' . date('Y-m-d'));
     }
     $this->log(' ');
     return $range;
 }
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(15);
$v = new sfValidatorInteger();
// ->clean()
$t->diag('->clean()');
$t->is($v->clean(12), 12, '->clean() returns the numbers unmodified');
$t->is($v->clean('12'), 12, '->clean() converts strings to integers');
try {
    $v->clean('not an integer');
    $t->fail('->clean() throws a sfValidatorError if the value is not an integer');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError if the value is not an integer');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');
}
try {
    $v->clean(12.3);
    $t->fail('->clean() throws a sfValidatorError if the value is not an integer');
    $t->skip('', 1);
} catch (sfValidatorError $e) {
    $t->pass('->clean() throws a sfValidatorError if the value is not an integer');
    $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError');