3 * This file is part of the PHPUnit_MockObject package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Invocation matcher which looks for sets of specific parameters in the invocations.
14 * Checks the parameters of the incoming invocations, the parameter list is
15 * checked against the defined constraints in $parameters. If the constraint
16 * is met it will return true in matches().
18 * It takes a list of match groups and and increases a call index after each invocation.
19 * So the first invocation uses the first group of constraints, the second the next and so on.
21 class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters
extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
26 private $_parameterGroups = array();
31 private $_invocations = array();
34 * @param array $parameterGroups
36 public function __construct(array $parameterGroups)
38 foreach ($parameterGroups as $index => $parameters) {
39 foreach ($parameters as $parameter) {
40 if (!($parameter instanceof \PHPUnit_Framework_Constraint
)) {
41 $parameter = new \
PHPUnit_Framework_Constraint_IsEqual($parameter);
43 $this->_parameterGroups
[$index][] = $parameter;
51 public function toString()
53 $text = 'with consecutive parameters';
59 * @param PHPUnit_Framework_MockObject_Invocation $invocation
62 public function matches(PHPUnit_Framework_MockObject_Invocation
$invocation)
64 $this->_invocations
[] = $invocation;
65 $callIndex = count($this->_invocations
) - 1;
66 $this->verifyInvocation($invocation, $callIndex);
71 public function verify()
73 foreach ($this->_invocations
as $callIndex => $invocation) {
74 $this->verifyInvocation($invocation, $callIndex);
79 * Verify a single invocation
81 * @param PHPUnit_Framework_MockObject_Invocation $invocation
82 * @param int $callIndex
83 * @throws PHPUnit_Framework_ExpectationFailedException
85 private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation
$invocation, $callIndex)
88 if (isset($this->_parameterGroups
[$callIndex])) {
89 $parameters = $this->_parameterGroups
[$callIndex];
91 // no parameter assertion for this call index
95 if ($invocation === null) {
96 throw new PHPUnit_Framework_ExpectationFailedException(
97 'Mocked method does not exist.'
101 if (count($invocation->parameters
) < count($parameters)) {
102 throw new PHPUnit_Framework_ExpectationFailedException(
104 'Parameter count for invocation %s is too low.',
105 $invocation->toString()
110 foreach ($parameters as $i => $parameter) {
111 $parameter->evaluate(
112 $invocation->parameters
[$i],
114 'Parameter %s for invocation #%d %s does not match expected ' .
118 $invocation->toString()