public function testEvaluateMessageFalse() { $v = new AlphaNumeric(null, 'This is alphanumeric', false); $this->assertEquals('This is alphanumeric', $v->getMessage()); $this->assertFalse($v->evaluate('abcdef123')); $this->assertTrue($v->evaluate('123456$#@')); }
public function testStringRandom() { $s = String::random(6); $this->assertEquals(6, strlen($s)); $s = String::random(6, String::ALPHANUM, String::LOWER); $val = new Validator\AlphaNumeric(); $this->assertTrue($val->evaluate($s)); $s = String::random(6, String::ALPHA, String::UPPER); $val = new Validator\Alpha(); $this->assertTrue($val->evaluate($s)); }
<?php require_once '../../bootstrap.php'; use Pop\Validator; try { // Create an alphanumeric validator $val = new Validator\AlphaNumeric(); $input = 'abcd1234'; // Evaluate if the input value meets the rule or not if (!$val->evaluate($input)) { echo $val->getMessage(); } else { echo 'The validator test passed. The string is alphanumeric.'; } } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }