Пример #1
0
 public function testCalculatingStringLength()
 {
     $data = [['input' => 'Τα ως υπ', 'expected' => 8], ['input' => '手配書 第十五章 第十八章 第十六章. 復讐者」', 'expected' => 24], ['input' => 'Verzameld daaronder gewijzigd al stichting ze na', 'expected' => 48], ['input' => 'this is a normal english sentence', 'expected' => 33], ['input' => 'foo', 'expected' => 3], ['input' => 'السلام عليكم', 'expected' => 12], ['input' => 'السلام عليكم ورحمه الله وبركاته', 'expected' => 31]];
     foreach ($data as $string) {
         $this->assertEquals($string['expected'], Utility::stringLength($string['input']));
     }
 }
Пример #2
0
 /**
  * Validate given data.
  *
  * @param mixed $input
  *
  * @return bool
  *
  * @throws \Sparta\Exceptions\InvalidValidatorArguments
  */
 public function isValid($input)
 {
     if (empty($this->getLength())) {
         throw new InvalidValidatorArguments($this->message('missing_arguments'));
     }
     $length = Utility::stringLength($input, $this->getEncoding());
     if ($length == false || $length != $this->getLength()) {
         $this->errors[] = sprintf($this->message('invalid_data'), $length, $this->getLength());
         return false;
     }
     return true;
 }