Phockito::_arguments_match PHP 메소드

_arguments_match() 공개 정적인 메소드

Checks if the two argument sets (passed as arrays) match. Simple serialized check for now, to be replaced by something that can handle anyString etc matchers later
public static _arguments_match ( $mockclass, $method, $a, $b )
    public static function _arguments_match($mockclass, $method, $a, $b)
    {
        // See if there are any defaults for the given method
        if (isset(self::$_defaults[$mockclass][$method])) {
            // If so, get them
            $defaults = self::$_defaults[$mockclass][$method];
            // And merge them with the passed args
            $a = $a + $defaults;
            $b = $b + $defaults;
        }
        // If two argument arrays are different lengths, automatic fail
        if (count($a) != count($b)) {
            return false;
        }
        // Step through each item
        $i = count($a);
        while ($i--) {
            $u = $a[$i];
            $v = $b[$i];
            // If the argument in $a is a hamcrest matcher, call match on it. WONTFIX: Can't check if function was passed a hamcrest matcher
            if (interface_exists('Hamcrest_Matcher') && ($u instanceof Hamcrest_Matcher || isset($u->__phockito_matcher))) {
                // The matcher can either be passed directly, or wrapped in a mock (for type safety reasons)
                $matcher = null;
                if ($u instanceof Hamcrest_Matcher) {
                    $matcher = $u;
                } elseif (isset($u->__phockito_matcher)) {
                    $matcher = $u->__phockito_matcher;
                }
                if ($matcher != null && !$matcher->matches($v)) {
                    return false;
                }
            } else {
                if (serialize($u) != serialize($v)) {
                    return false;
                }
            }
        }
        return true;
    }

Usage Example

예제 #1
0
 /**
  * Store the method and args we're stubbing
  */
 private function __phockito_setMethod($method, $args)
 {
     $instance = $this->instance;
     $this->method = $method;
     if (!isset(Phockito::$_responses[$instance])) {
         Phockito::$_responses[$instance] = array();
     }
     if (!isset(Phockito::$_responses[$instance][$method])) {
         Phockito::$_responses[$instance][$method] = array();
     }
     $this->i = count(Phockito::$_responses[$instance][$method]);
     foreach (Phockito::$_responses[$instance][$method] as $i => &$matcher) {
         if (Phockito::_arguments_match($this->class, $method, $matcher['args'], $args)) {
             $this->i = $i;
             break;
         }
     }
     Phockito::$_responses[$instance][$method][$this->i] = array('args' => $args, 'steps' => array());
 }
All Usage Examples Of Phockito::_arguments_match