class PHPUnit_Framework_MockObject_Matcher_Parameters

Invocation matcher which looks for specific parameters in the invocations.

Checks the parameters of all incoming invocations, the parameter list is checked against the defined constraints in $parameters. If the constraint is met it will return true in matches().

@package PHPUnit_MockObject @author Sebastian Bergmann <sb@sebastian-bergmann.de> @copyright 2010-2013 Sebastian Bergmann <sb@sebastian-bergmann.de> @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License @version Release: @package_version@ @link http://github.com/sebastianbergmann/phpunit-mock-objects @since Class available since Release 1.0.0

Hierarchy

Expanded class hierarchy of PHPUnit_Framework_MockObject_Matcher_Parameters

File

drupal/core/vendor/phpunit/phpunit-mock-objects/PHPUnit/Framework/MockObject/Matcher/Parameters.php, line 60

View source
class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation {

  /**
   * @var array
   */
  protected $parameters = array();

  /**
   * @var PHPUnit_Framework_MockObject_Invocation
   */
  protected $invocation;

  /**
   * @param array $parameters
   */
  public function __construct(array $parameters) {
    foreach ($parameters as $parameter) {
      if (!$parameter instanceof PHPUnit_Framework_Constraint) {
        $parameter = new PHPUnit_Framework_Constraint_IsEqual($parameter);
      }
      $this->parameters[] = $parameter;
    }
  }

  /**
   * @return string
   */
  public function toString() {
    $text = 'with parameter';
    foreach ($this->parameters as $index => $parameter) {
      if ($index > 0) {
        $text .= ' and';
      }
      $text .= ' ' . $index . ' ' . $parameter
        ->toString();
    }
    return $text;
  }

  /**
   * @param  PHPUnit_Framework_MockObject_Invocation $invocation
   * @return boolean
   */
  public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) {
    $this->invocation = $invocation;
    $this
      ->verify();
    return count($invocation->parameters) < count($this->parameters);
  }

  /**
   * 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) {
      $parameter
        ->evaluate($this->invocation->parameters[$i], sprintf('Parameter %s for invocation %s does not match expected ' . 'value.', $i, $this->invocation
        ->toString()));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PHPUnit_Framework_MockObject_Matcher_Parameters::$invocation protected property
PHPUnit_Framework_MockObject_Matcher_Parameters::$parameters protected property
PHPUnit_Framework_MockObject_Matcher_Parameters::matches public function Overrides PHPUnit_Framework_MockObject_Matcher_Invocation::matches
PHPUnit_Framework_MockObject_Matcher_Parameters::toString public function Overrides PHPUnit_Framework_SelfDescribing::toString
PHPUnit_Framework_MockObject_Matcher_Parameters::verify public function 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. Overrides PHPUnit_Framework_MockObject_Matcher_StatelessInvocation::verify
PHPUnit_Framework_MockObject_Matcher_Parameters::__construct public function
PHPUnit_Framework_MockObject_Matcher_StatelessInvocation::invoked public function Registers the invocation $invocation in the object as being invoked. This will only occur after matches() returns true which means the current invocation is the correct one. Overrides PHPUnit_Framework_MockObject_Matcher_Invocation::invoked