Development

Changeset 5758

You must first sign up to be able to contribute.

Changeset 5758

Show
Ignore:
Timestamp:
10/30/07 08:14:50 (1 year ago)
Author:
dwhittle
Message:

dwhittle: merged validation changes from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dwhittle/lib/validator/sfValidator.class.php

    r5651 r5758  
    273273  { 
    274274  } 
     275 
     276  /** 
     277   * Returns a string representation of this validator. 
     278   * 
     279   * @param  integer Indentation (number of spaces before each line) 
     280   * 
     281   * @return string  The string representation of the validator 
     282   */ 
     283  public function asString($indent = 0) 
     284  { 
     285    $options = $this->getOptionsWithoutDefaults(); 
     286    $messages = $this->getMessagesWithoutDefaults(); 
     287 
     288    return sprintf('%s%s(%s%s)', 
     289      str_repeat(' ', $indent), 
     290      str_replace('sfValidator', '', get_class($this)), 
     291      $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), 
     292      $messages ? ', '.sfYamlInline::dump($messages) : '' 
     293    ); 
     294  } 
     295 
     296  /** 
     297   * Returns all options with non default values. 
     298   * 
     299   * @return string  A string representation of the options 
     300   */ 
     301  protected function getOptionsWithoutDefaults() 
     302  { 
     303    $options = $this->options; 
     304 
     305    // remove default option values 
     306    $reflection = new ReflectionClass(get_class($this)); 
     307    $default = $reflection->newInstanceArgs(func_get_args()); 
     308    foreach ($default->getOptions() as $key => $value) 
     309    { 
     310      if (array_key_exists($key, $options) && $options[$key] === $value) 
     311      { 
     312        unset($options[$key]); 
     313      } 
     314    } 
     315 
     316    return $options; 
     317  } 
     318 
     319  /** 
     320   * Returns all error messages with non default values. 
     321   * 
     322   * @return string A string representation of the error messages 
     323   */ 
     324  protected function getMessagesWithoutDefaults() 
     325  { 
     326    $messages = $this->messages; 
     327 
     328    // remove default option values 
     329    $reflection = new ReflectionClass(get_class($this)); 
     330    $default = $reflection->newInstanceArgs(func_get_args()); 
     331    foreach ($default->getMessages() as $key => $value) 
     332    { 
     333      if (array_key_exists($key, $messages) && $messages[$key] === $value) 
     334      { 
     335        unset($messages[$key]); 
     336      } 
     337    } 
     338 
     339    return $messages; 
     340  } 
    275341} 
  • branches/dwhittle/lib/validator/sfValidatorAll.class.php

    r5651 r5758  
    114114    return $clean; 
    115115  } 
     116 
     117  /** 
     118   * @see sfValidator 
     119   */ 
     120  public function asString($indent = 0) 
     121  { 
     122    $validators = ''; 
     123    for ($i = 0, $max = count($this->validators); $i < $max; $i++) 
     124    { 
     125      $validators .= "\n".$this->validators[$i]->asString($indent + 2)."\n"; 
     126 
     127      if ($i < $max - 1) 
     128      { 
     129        $validators .= str_repeat(' ', $indent + 2).'and'; 
     130      } 
     131 
     132      if ($i == $max - 2) 
     133      { 
     134        $options = $this->getOptionsWithoutDefaults(); 
     135        $messages = $this->getMessagesWithoutDefaults(); 
     136 
     137        if ($options || $messages) 
     138        { 
     139          $validators .= sprintf('(%s%s)', 
     140            $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), 
     141            $messages ? ', '.sfYamlInline::dump($messages) : '' 
     142          ); 
     143        } 
     144      } 
     145    } 
     146 
     147    return sprintf("%s(%s%s)", 
     148      str_repeat(' ', $indent), 
     149      $validators, 
     150      str_repeat(' ', $indent) 
     151    ); 
     152  } 
    116153} 
  • branches/dwhittle/lib/validator/sfValidatorAny.class.php

    r5651 r5758  
    108108    throw new sfValidatorErrorSchema($this, $errors); 
    109109  } 
     110 
     111  /** 
     112   * @see sfValidator 
     113   */ 
     114  public function asString($indent = 0) 
     115  { 
     116    $validators = ''; 
     117    for ($i = 0, $max = count($this->validators); $i < $max; $i++) 
     118    { 
     119      $validators .= "\n".$this->validators[$i]->asString($indent + 2)."\n"; 
     120 
     121      if ($i < $max - 1) 
     122      { 
     123        $validators .= str_repeat(' ', $indent + 2).'or'; 
     124      } 
     125 
     126      if ($i == $max - 2) 
     127      { 
     128        $options = $this->getOptionsWithoutDefaults(); 
     129        $messages = $this->getMessagesWithoutDefaults(); 
     130 
     131        if ($options || $messages) 
     132        { 
     133          $validators .= sprintf('(%s%s)', 
     134            $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), 
     135            $messages ? ', '.sfYamlInline::dump($messages) : '' 
     136          ); 
     137        } 
     138      } 
     139    } 
     140 
     141    return sprintf("%s(%s%s)", 
     142      str_repeat(' ', $indent), 
     143      $validators, 
     144      str_repeat(' ', $indent) 
     145    ); 
     146  } 
    110147} 
  • branches/dwhittle/lib/validator/sfValidatorCallback.class.php

    r5582 r5758  
    1919class sfValidatorCallback extends sfValidator 
    2020{ 
    21   protected 
    22     $callback = null; 
    23  
    2421  /** 
    2522   * Constructor. 
    2623   * 
    27    * The first argument can be any valid PHP callback. 
     24   * Available options: 
    2825   * 
    29    * @param mixed A PHP callback 
    30    * @param array An array of options 
    31    * @param array An array of error messages 
     26   *  * callback: A valid PHP callback 
    3227   * 
    3328   * @see sfValidator 
    3429   */ 
    35   public function __construct($callback, $options = array(), $messages = array()) 
     30  public function __construct($options = array(), $messages = array()) 
    3631  { 
    37     $this->callback = $callback; 
     32    if (!isset($options['callback'])) 
     33    { 
     34      throw new sfException('The "callback" option is mandatory.'); 
     35    } 
    3836 
    3937    parent::__construct($options, $messages); 
     
    5351  protected function doClean($value) 
    5452  { 
    55     return call_user_func($this->callback, $this, $value); 
     53    return call_user_func($this->getOption('callback'), $this, $value); 
     54  } 
     55 
     56  /** 
     57   * @see sfValidator 
     58   */ 
     59  protected function getOptionsWithoutDefaults() 
     60  { 
     61    return parent::getOptionsWithoutDefaults(array('callback' => array('--fake--'))); 
     62  } 
     63 
     64  /** 
     65   * @see sfValidator 
     66   */ 
     67  protected function getMessagesWithoutDefaults() 
     68  { 
     69    return parent::getMessagesWithoutDefaults(array('callback' => array('--fake--'))); 
    5670  } 
    5771} 
  • branches/dwhittle/lib/validator/sfValidatorChoice.class.php

    r5582 r5758  
    2222   * Constructor. 
    2323   * 
    24    * @param array  An array of expected values 
    25    * @param array  An array of options 
    26    * @param array  An array of error messages 
     24   * Available options: 
     25   * 
     26   * * choices: An array of expected values 
    2727   * 
    2828   * @see sfValidator 
    2929   */ 
    30   public function __construct($expected, $options = array(), $messages = array()) 
     30  public function __construct($options = array(), $messages = array()) 
    3131  { 
    32     $options['expected'] = $expected; 
     32    if (!isset($options['choices'])) 
     33    { 
     34      throw new sfException('The "choices" option is mandatory.'); 
     35    } 
    3336 
    3437    parent::__construct($options, $messages); 
     
    4043  protected function doClean($value) 
    4144  { 
    42     if (!in_array($value, $this->getOption('expected'))) 
     45    if (!in_array($value, $this->getOption('choices'))) 
    4346    { 
    4447      throw new sfValidatorError($this, 'invalid', array('value' => $value)); 
     
    4750    return $value; 
    4851  } 
     52 
     53  /** 
     54   * @see sfValidator 
     55   */ 
     56  protected function getOptionsWithoutDefaults() 
     57  { 
     58    return parent::getOptionsWithoutDefaults(array('choices' => array('--fake--'))); 
     59  } 
     60 
     61  /** 
     62   * @see sfValidator 
     63   */ 
     64  protected function getMessagesWithoutDefaults() 
     65  { 
     66    return parent::getMessagesWithoutDefaults(array('choices' => array('--fake--'))); 
     67  } 
    4968} 
  • branches/dwhittle/lib/validator/sfValidatorChoiceMany.class.php

    r5582 r5758  
    1717 * @version    SVN: $Id$ 
    1818 */ 
    19 class sfValidatorChoiceMany extends sfValidator 
     19class sfValidatorChoiceMany extends sfValidatorChoice 
    2020{ 
    21   /** 
    22    * Constructor. 
    23    * 
    24    * @param array  An array of expected values 
    25    * @param array  An array of options 
    26    * @param array  An array of error messages 
    27    * 
    28    * @see sfValidator 
    29    */ 
    30   public function __construct($expected, $options = array(), $messages = array()) 
    31   { 
    32     $options['expected'] = $expected; 
    33  
    34     parent::__construct($options, $messages); 
    35   } 
    36  
    3721  /** 
    3822   * @see sfValidator 
     
    4731    foreach ($values as $value) 
    4832    { 
    49       if (!in_array($value, $this->getOption('expected'))) 
     33      if (!in_array($value, $this->getOption('choices'))) 
    5034      { 
    5135        throw new sfValidatorError($this, 'invalid', array('value' => $value)); 
  • branches/dwhittle/lib/validator/sfValidatorDecorator.class.php

    r5651 r5758  
    153153    return $this->getValidator()->getErrorCodes(); 
    154154  } 
     155 
     156  /** 
     157   * @see sfValidator 
     158   */ 
     159  public function asString($indent = 0) 
     160  { 
     161    return $this->getValidator()->asString($indent); 
     162  } 
    155163} 
  • branches/dwhittle/lib/validator/sfValidatorEmail.class.php

    r5582 r5758  
    2424  public function __construct($options = array(), $messages = array()) 
    2525  { 
    26     parent::__construct('/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i', $options, $messages); 
     26    $options['pattern'] = '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i'; 
     27 
     28    parent::__construct($options, $messages); 
    2729  } 
    2830} 
  • branches/dwhittle/lib/validator/sfValidatorRegex.class.php

    r5582 r5758  
    2222   * Constructor. 
    2323   * 
    24    * @param string A regex pattern compatible with PCRE 
    25    * @param array  An array of options 
    26    * @param array  An array of error messages 
     24   * Available options: 
     25   * 
     26   * * pattern: A regex pattern compatible with PCRE 
    2727   * 
    2828   * @see sfValidator 
    2929   */ 
    30   public function __construct($pattern, $options = array(), $messages = array()) 
     30  public function __construct($options = array(), $messages = array()) 
    3131  { 
    32     $options['pattern'] = $pattern; 
     32    if (!isset($options['pattern'])) 
     33    { 
     34      throw new sfException('The "pattern" option is mandatory.'); 
     35    } 
    3336 
    3437    parent::__construct($options, $messages); 
     
    4952    return $clean; 
    5053  } 
     54 
     55  /** 
     56   * @see sfValidator 
     57   */ 
     58  protected function getOptionsWithoutDefaults() 
     59  { 
     60    return parent::getOptionsWithoutDefaults(array('pattern' => array('--fake--'))); 
     61  } 
     62 
     63  /** 
     64   * @see sfValidator 
     65   */ 
     66  protected function getMessagesWithoutDefaults() 
     67  { 
     68    return parent::getMessagesWithoutDefaults(array('pattern' => array('--fake--'))); 
     69  } 
    5170} 
  • branches/dwhittle/lib/validator/sfValidatorSchema.class.php

    r5651 r5758  
    256256    return $this->fields; 
    257257  } 
     258 
     259  /** 
     260   * @see sfValidator 
     261   */ 
     262  public function asString($indent = 0) 
     263  { 
     264    throw new sfException('Unable to convert a sfValidatorSchema to string.'); 
     265  } 
    258266} 
  • branches/dwhittle/lib/validator/sfValidatorSchemaCompare.class.php

    r5582 r5758  
    105105    if (!$valid) 
    106106    { 
    107       throw new sfValidatorError($this, 'invalid', array('value' => $values)); 
     107      throw new sfValidatorError($this, 'invalid', array( 
     108        'left_field'  => $leftValue, 
     109        'right_field' => $rightValue, 
     110        'operator'    => $this->getOption('operator'), 
     111      )); 
    108112    } 
    109113 
    110114    return $values; 
    111115  } 
     116 
     117  /** 
     118   * @see sfValidator 
     119   */ 
     120  public function asString($indent = 0) 
     121  { 
     122    $options = $this->getOptionsWithoutDefaults('--fake--', '--', '--fake--'); 
     123    $messages = $this->getMessagesWithoutDefaults('--fake--', '--', '--fake--'); 
     124    unset($options['leftField'], $options['operator'], $options['rightField']); 
     125 
     126    $arguments = ''; 
     127    if ($options || $messages) 
     128    { 
     129      $arguments = sprintf('(%s%s)', 
     130        $options ? sfYamlInline::dump($options) : ($messages ? '{}' : ''), 
     131        $messages ? ', '.sfYamlInline::dump($messages) : '' 
     132      ); 
     133    } 
     134 
     135    return sprintf('%s%s %s%s %s', 
     136      str_repeat(' ', $indent), 
     137      $this->getOption('leftField'), 
     138      $this->getOption('operator'), 
     139      $arguments, 
     140      $this->getOption('rightField') 
     141    ); 
     142  } 
    112143} 
  • branches/dwhittle/lib/validator/sfValidatorSchemaFilter.class.php

    r5651 r5758  
    6666    return $values; 
    6767  } 
     68 
     69  /** 
     70   * @see sfValidator 
     71   */ 
     72  public function asString($indent = 0) 
     73  { 
     74    return sprintf('%s%s:%s', str_repeat(' ', $indent), $this->getOption('field'), $this->getOption('validator')->asString(0)); 
     75  } 
    6876} 
  • branches/dwhittle/lib/validator/sfValidatorSchemaForEach.class.php

    r5582 r5758  
    4141    parent::__construct($fields, $options, $messages); 
    4242  } 
     43 
     44  /** 
     45   * @see sfValidator 
     46   */ 
     47  public function asString($indent = 0) 
     48  { 
     49    throw new sfException('Unable to convert a sfValidatorSchemaForEach to string.'); 
     50  } 
    4351} 
  • branches/dwhittle/lib/validator/sfValidatorUrl.class.php

    r5582 r5758  
    2424  public function __construct($options = array(), $messages = array()) 
    2525  { 
    26     $pattern = '~^ 
     26    $options['pattern'] = '~^ 
    2727      https?://                               # http or https 
    2828      ( 
     
    3535    $~ix'; 
    3636 
    37     parent::__construct($pattern, $options, $messages); 
     37    parent::__construct($options, $messages); 
    3838  } 
    3939} 
  • branches/dwhittle/test/unit/validator/sfValidatorAllTest.php

    r5651 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(14, new lime_output_color()); 
     13$t = new lime_test(16, new lime_output_color()); 
    1414 
    1515$v1 = new sfValidatorString(array('max_length' => 3)); 
     
    8686  $t->is(!$e instanceof sfValidatorErrorSchema, 'max_length', '->clean() throws a sfValidatorError if invalid message is not empty'); 
    8787} 
     88 
     89// ->asString() 
     90$t->diag('->asString()'); 
     91$v1 = new sfValidatorString(array('max_length' => 3)); 
     92$v2 = new sfValidatorString(array('min_length' => 3)); 
     93$v = new sfValidatorAll(array($v1, $v2)); 
     94$t->is($v->asString(), <<<EOF 
     95( 
     96  String({ max_length: 3 }) 
     97  and 
     98  String({ min_length: 3 }) 
     99) 
     100EOF 
     101, '->asString() returns a string representation of the validator'); 
     102 
     103$v = new sfValidatorAll(array($v1, $v2), array(), array('required' => 'This is required.')); 
     104$t->is($v->asString(), <<<EOF 
     105( 
     106  String({ max_length: 3 }) 
     107  and({}, { required: 'This is required.' }) 
     108  String({ min_length: 3 }) 
     109) 
     110EOF 
     111, '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorAnyTest.php

    r5651 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(16, new lime_output_color()); 
     13$t = new lime_test(18, new lime_output_color()); 
    1414 
    1515$v1 = new sfValidatorString(array('max_length' => 3)); 
     
    9292$v2->setOption('min_length', 1); 
    9393$t->is($v->clean('foo'), 'foo', '->clean() returns the string unmodified'); 
     94 
     95// ->asString() 
     96$t->diag('->asString()'); 
     97$v1 = new sfValidatorString(array('max_length' => 3)); 
     98$v2 = new sfValidatorString(array('min_length' => 3)); 
     99$v = new sfValidatorAny(array($v1, $v2)); 
     100$t->is($v->asString(), <<<EOF 
     101( 
     102  String({ max_length: 3 }) 
     103  or 
     104  String({ min_length: 3 }) 
     105) 
     106EOF 
     107, '->asString() returns a string representation of the validator'); 
     108 
     109$v = new sfValidatorAny(array($v1, $v2), array(), array('required' => 'This is required.')); 
     110$t->is($v->asString(), <<<EOF 
     111( 
     112  String({ max_length: 3 }) 
     113  or({}, { required: 'This is required.' }) 
     114  String({ min_length: 3 }) 
     115) 
     116EOF 
     117, '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorCallbackTest.php

    r5582 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(3, new lime_output_color()); 
     13$t = new lime_test(5, new lime_output_color()); 
    1414 
    1515function clean_test($validator, $value) 
     
    2323} 
    2424 
    25 $v = new sfValidatorCallback('clean_test'); 
     25// __construct() 
     26$t->diag('__construct()'); 
     27try 
     28
     29  new sfValidatorCallback(); 
     30  $t->fail('__construct() throws an sfException if you don\'t pass a callback option'); 
     31
     32catch (sfException $e) 
     33
     34  $t->pass('__construct() throws an sfException if you don\'t pass a callback option'); 
     35
     36 
     37$v = new sfValidatorCallback(array('callback' => 'clean_test')); 
    2638 
    2739// ->clean() 
     
    4153$t->diag('->configure()'); 
    4254$t->is($v->clean(''), null, '->configure() switch required to false by default'); 
     55 
     56// ->asString() 
     57$t->diag('->asString()'); 
     58$t->is($v->asString(), 'Callback({ callback: clean_test })', '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorChoiceManyTest.php

    r5582 r5758  
    1313$t = new lime_test(5, new lime_output_color()); 
    1414 
    15 $v = new sfValidatorChoiceMany(array('foo', 'bar')); 
     15$v = new sfValidatorChoiceMany(array('choices' => array('foo', 'bar'))); 
    1616 
    1717// ->clean() 
  • branches/dwhittle/test/unit/validator/sfValidatorChoiceTest.php

    r5582 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(3, new lime_output_color()); 
     13$t = new lime_test(5, new lime_output_color()); 
    1414 
    15 $v = new sfValidatorChoice(array('foo', 'bar')); 
     15// __construct() 
     16$t->diag('__construct()'); 
     17try 
     18
     19  new sfValidatorChoice(); 
     20  $t->fail('__construct() throws an sfException if you don\'t pass an expected option'); 
     21
     22catch (sfException $e) 
     23
     24  $t->pass('__construct() throws an sfException if you don\'t pass an expected option'); 
     25
     26 
     27$v = new sfValidatorChoice(array('choices' => array('foo', 'bar'))); 
    1628 
    1729// ->clean() 
     
    2941  $t->pass('->clean() throws an sfValidatorError if the value is not an expected value'); 
    3042} 
     43 
     44// ->asString() 
     45$t->diag('->asString()'); 
     46$t->is($v->asString(), 'Choice({ choices: [foo, bar] })', '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorRegexTest.php

    r5582 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(3, new lime_output_color()); 
     13$t = new lime_test(5, new lime_output_color()); 
    1414 
    15 $v = new sfValidatorRegex('/^[0-9]+$/'); 
     15// __construct() 
     16$t->diag('__construct()'); 
     17try 
     18
     19  new sfValidatorRegex(); 
     20  $t->fail('__construct() throws an sfException if you don\'t pass a pattern option'); 
     21
     22catch (sfException $e) 
     23
     24  $t->pass('__construct() throws an sfException if you don\'t pass a pattern option'); 
     25
     26 
     27$v = new sfValidatorRegex(array('pattern' => '/^[0-9]+$/')); 
    1628 
    1729// ->getErrorCodes() 
     
    3244  $t->pass('->clean() throws an sfValidatorError if the value does not match the pattern'); 
    3345} 
     46 
     47// ->asString() 
     48$t->diag('->asString()'); 
     49$t->is($v->asString(), 'Regex({ pattern: \'/^[0-9]+$/\' })', '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorSchemaCompareTest.php

    r5582 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(17, new lime_output_color()); 
     13$t = new lime_test(19, new lime_output_color()); 
    1414 
    1515$v = new sfValidatorSchemaCompare('left', sfValidatorSchemaCompare::EQUAL, 'right'); 
     
    6565  $t->pass('->clean() throws an sfException exception if the first argument is not an array of value'); 
    6666} 
     67 
     68// ->asString() 
     69$t->diag('->asString()'); 
     70$v = new sfValidatorSchemaCompare('left', '==', 'right'); 
     71$t->is($v->asString(), 'left == right', '->asString() returns a string representation of the validator'); 
     72 
     73$v = new sfValidatorSchemaCompare('left', '==', 'right', array(), array('required' => 'This is required.')); 
     74$t->is($v->asString(), 'left ==({}, { required: \'This is required.\' }) right', '->asString() returns a string representation of the validator'); 
  • branches/dwhittle/test/unit/validator/sfValidatorTest.php

    r5651 r5758  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(23, new lime_output_color()); 
     13$t = new lime_test(27, new lime_output_color()); 
    1414 
    1515class ValidatorIdentity extends sfValidator 
     
    121121sfValidator::setCharset('ISO-8859-1'); 
    122122$t->is(sfValidator::getCharset(), 'ISO-8859-1', '::setCharset() changes the charset to use for validators'); 
     123 
     124// ->asString() 
     125$t->diag('->asString()'); 
     126$v = new ValidatorIdentity(); 
     127$t->is($v->asString(), 'ValidatorIdentity()', '->asString() returns a string representation of the validator'); 
     128$v->setOption('required', false); 
     129$v->setOption('foo', 'foo'); 
     130$t->is($v->asString(), 'ValidatorIdentity({ required: false, foo: foo })', '->asString() returns a string representation of the validator'); 
     131 
     132$v->setMessage('required', 'This is required.'); 
     133$t->is($v->asString(), 'ValidatorIdentity({ required: false, foo: foo }, { required: \'This is required.\' })', '->asString() returns a string representation of the validator'); 
     134 
     135$v = new ValidatorIdentity(); 
     136$v->setMessage('required', 'This is required.'); 
     137$t->is($v->asString(), 'ValidatorIdentity({}, { required: \'This is required.\' })', '->asString() returns a string representation of the validator');