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
Expanded class hierarchy of PHPUnit_Framework_MockObject_Matcher_Parameters
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()));
}
}
}