Ejemplo n.º 1
0
 /**
  * Returns the user defined matcher description
  * 
  * @return string
  */
 public function getDescription()
 {
     $matcher = MatcherRepository::get($this->_matcher);
     $match = call_user_func_array($matcher, $this->_expected);
     return $match['description']($this->_actual);
 }
Ejemplo n.º 2
0
 /**
  * Invokes a matcher
  * 
  * @param string $method
  * @param array $args
  * @return boolean|mixed
  */
 public function __call($method, $args)
 {
     if (in_array($method, $this->_matchers)) {
         $this->setExpectedValue($args);
         $this->createMatcher($method);
         $this->performMatching();
         return true;
     }
     if (\PHPSpec\Matcher\MatcherRepository::has($method)) {
         $this->setExpectedValue($args);
         $expected = !is_array($this->getExpectedValue()) ? array($this->getExpectedValue()) : $this->getExpectedValue();
         $this->_matcher = new \PHPSpec\Matcher\UserDefined($method, $expected);
         $this->performMatching();
         return true;
     }
     if (method_exists($this->_actualValue, '__call')) {
         $parentInterceptor = new \ReflectionMethod($this->_actualValue, '__call');
         return $parentInterceptor->invokeArgs($this->_actualValue, $args);
     }
     if (!$this instanceof Interceptor\Object && $this->_expectation !== null) {
         throw new \BadMethodCallException("Call to undefined method {$method}");
     }
 }
Ejemplo n.º 3
0
/**
 * Defines a custom matcher
 * 
 * @param string   $matcherName
 * @param \Closure $matcherDefinition
 */
function define($matcherName, $matcherDefinition)
{
    \PHPSpec\Matcher\MatcherRepository::add($matcherName, $matcherDefinition);
}