2 // @codingStandardsIgnoreFile
4 * This file is part of the PHPUnit_MockObject package.
6 * (c) Sebastian Bergmann <sebastian@phpunit.de>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Invocation matcher which looks for sets of specific parameters in the invocations.
15 * Checks the parameters of the incoming invocations, the parameter list is
16 * checked against the defined constraints in $parameters. If the constraint
17 * is met it will return true in matches().
19 * It takes a list of match groups and and increases a call index after each invocation.
20 * So the first invocation uses the first group of constraints, the second the next and so on.
22 class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters
extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
27 private $_parameterGroups = array();
32 private $_invocations = array();
35 * @param array $parameterGroups
37 public function __construct(array $parameterGroups)
39 foreach ($parameterGroups as $index => $parameters) {
40 foreach ($parameters as $parameter) {
41 if (!($parameter instanceof \PHPUnit_Framework_Constraint
)) {
42 $parameter = new \
PHPUnit_Framework_Constraint_IsEqual($parameter);
44 $this->_parameterGroups
[$index][] = $parameter;
52 public function toString()
54 $text = 'with consecutive parameters';
60 * @param PHPUnit_Framework_MockObject_Invocation $invocation
63 public function matches(PHPUnit_Framework_MockObject_Invocation
$invocation)
65 $this->_invocations
[] = $invocation;
66 $callIndex = count($this->_invocations
) - 1;
67 $this->verifyInvocation($invocation, $callIndex);
72 public function verify()
74 foreach ($this->_invocations
as $callIndex => $invocation) {
75 $this->verifyInvocation($invocation, $callIndex);
80 * Verify a single invocation
82 * @param PHPUnit_Framework_MockObject_Invocation $invocation
83 * @param int $callIndex
84 * @throws PHPUnit_Framework_ExpectationFailedException
86 private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation
$invocation, $callIndex)
89 if (isset($this->_parameterGroups
[$callIndex])) {
90 $parameters = $this->_parameterGroups
[$callIndex];
92 // no parameter assertion for this call index
96 if ($invocation === null) {
97 throw new PHPUnit_Framework_ExpectationFailedException(
98 'Mocked method does not exist.'
102 if (count($invocation->parameters
) < count($parameters)) {
103 throw new PHPUnit_Framework_ExpectationFailedException(
105 'Parameter count for invocation %s is too low.',
106 $invocation->toString()
111 foreach ($parameters as $i => $parameter) {
112 $parameter->evaluate(
113 $invocation->parameters
[$i],
115 'Parameter %s for invocation #%d %s does not match expected ' .
119 $invocation->toString()