Coduo\PHPMatcher\Matcher\UuidMatcher::match PHP Method

match() public method

{@inheritDoc}
public match ( $value, $pattern )
    public function match($value, $pattern)
    {
        if (!is_string($value)) {
            $this->error = sprintf("%s \"%s\" is not a valid UUID: not a string.", gettype($value), new StringConverter($value));
            return false;
        }
        if (1 !== preg_match(self::UUID_FORMAT_PATTERN, $value)) {
            $this->error = sprintf("%s \"%s\" is not a valid UUID: invalid format.", gettype($value), $value);
            return false;
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * @dataProvider negativeMatchDescription
  */
 public function test_negative_match_description($value, $pattern, $error)
 {
     $this->matcher->match($value, $pattern);
     $this->assertEquals($error, $this->matcher->getError());
 }