Tester\Assert::isMatching PHP Method

isMatching() public static method

Compares using mask.
public static isMatching ( $pattern, $actual, $strict = FALSE ) : boolean
return boolean
    public static function isMatching($pattern, $actual, $strict = FALSE)
    {
        if (!is_string($pattern) && !is_scalar($actual)) {
            throw new \Exception('Value and pattern must be strings.');
        }
        $old = ini_set('pcre.backtrack_limit', '10000000');
        if (!self::isPcre($pattern)) {
            $utf8 = preg_match('#\\x80-\\x{10FFFF}]#u', $pattern) ? 'u' : '';
            $suffix = ($strict ? '\\z#sU' : '\\s*$#sU') . $utf8;
            $patterns = static::$patterns + ['[.\\\\+*?[^$(){|\\#]' => '\\$0', '\\x00' => '\\x00', '[\\t ]*\\r?\\n' => '[\\t ]*\\r?\\n'];
            $pattern = '#^' . preg_replace_callback('#' . implode('|', array_keys($patterns)) . '#U' . $utf8, function ($m) use($patterns) {
                foreach ($patterns as $re => $replacement) {
                    $s = preg_replace("#^{$re}\\z#", str_replace('\\', '\\\\', $replacement), $m[0], 1, $count);
                    if ($count) {
                        return $s;
                    }
                }
            }, rtrim($pattern, " \t\n\r")) . $suffix;
        }
        $res = preg_match($pattern, $actual);
        ini_set('pcre.backtrack_limit', $old);
        if ($res === FALSE || preg_last_error()) {
            throw new \Exception('Error while executing regular expression. (PREG Error Code ' . preg_last_error() . ')');
        }
        return (bool) $res;
    }

Usage Example

Example #1
1
 private function assessOutputMatch(Job $job, $content)
 {
     if (!Tester\Assert::isMatching($content, $job->getOutput())) {
         Dumper::saveOutput($job->getFile(), $job->getOutput(), '.actual');
         Dumper::saveOutput($job->getFile(), $content, '.expected');
         return array(Runner::FAILED, 'Failed: output should match ' . Dumper::toLine(rtrim($content)));
     }
 }
All Usage Examples Of Tester\Assert::isMatching