示例#1
0
    /**
     * Checks if the invocation $invocation matches the current rules. If it
     * does the matcher will get the invoked() method called which should check 
     * if an expectation is met.
     *
     * @param  PHPUnit_Framework_MockObject_Invocation $invocation
     *         Object containing information on a mocked or stubbed method which
     *         was invoked.
     * @return bool
     * @throws PHPUnit_Framework_ExpectationFailedException
     */
    public function verify()
    {
        if ($this->invocation === NULL) {
            throw new PHPUnit_Framework_ExpectationFailedException(
              'Mocked method does not exist.'
            );
        }

        if (count($this->invocation->parameters) < count($this->parameters)) {
            throw new PHPUnit_Framework_ExpectationFailedException(
              sprintf(
                'Parameter count for invocation %s is too low.',

                $this->invocation->toString()
              )
            );
        }

        foreach ($this->parameters as $i => $parameter) {
            if (!$parameter->evaluate($this->invocation->parameters[$i])) {
                $parameter->fail(
                  $this->invocation->parameters[$i],
                  sprintf(
                    'Parameter %s for invocation %s does not match expected ' .
                    'value.',

                    $i,
                    $this->invocation->toString()
                  )
                );
            }
        }
    }
 /**
  * Verify a single invocation
  *
  * @param  PHPUnit_Framework_MockObject_Invocation $invocation
  * @param  int $callIndex
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex)
 {
     if (isset($this->_parameterGroups[$callIndex])) {
         $parameters = $this->_parameterGroups[$callIndex];
     } else {
         // no parameter assertion for this call index
         return;
     }
     if ($invocation === null) {
         throw new PHPUnit_Framework_ExpectationFailedException('Mocked method does not exist.');
     }
     if (count($invocation->parameters) < count($parameters)) {
         throw new PHPUnit_Framework_ExpectationFailedException(sprintf('Parameter count for invocation %s is too low.', $invocation->toString()));
     }
     foreach ($parameters as $i => $parameter) {
         $parameter->evaluate($invocation->parameters[$i], sprintf('Parameter %s for invocation #%d %s does not match expected ' . 'value.', $i, $callIndex, $invocation->toString()));
     }
 }
示例#3
0
文件: Parameters.php 项目: ezrra/PHP
 /**
  * Checks if the invocation $invocation matches the current rules. If it
  * does the matcher will get the invoked() method called which should check
  * if an expectation is met.
  *
  * @param PHPUnit_Framework_MockObject_Invocation $invocation
  *                                                            Object containing information on a mocked or stubbed method which
  *                                                            was invoked.
  *
  * @return bool
  *
  * @throws PHPUnit_Framework_ExpectationFailedException
  */
 public function verify()
 {
     if ($this->invocation === null) {
         throw new PHPUnit_Framework_ExpectationFailedException('Mocked method does not exist.');
     }
     if (count($this->invocation->parameters) < count($this->parameters)) {
         $message = 'Parameter count for invocation %s is too low.';
         // The user called `->with($this->anything())`, but may have meant
         // `->withAnyParameters()`.
         //
         // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199
         if (count($this->parameters) === 1 && get_class($this->parameters[0]) === 'PHPUnit_Framework_Constraint_IsAnything') {
             $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.";
         }
         throw new PHPUnit_Framework_ExpectationFailedException(sprintf($message, $this->invocation->toString()));
     }
     foreach ($this->parameters as $i => $parameter) {
         $parameter->evaluate($this->invocation->parameters[$i], sprintf('Parameter %s for invocation %s does not match expected ' . 'value.', $i, $this->invocation->toString()));
     }
     return true;
 }