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 checks if a method was invoked at a certain index.
14 * If the expected index number does not match the current invocation index it
15 * will not match which means it skips all method and parameter matching. Only
16 * once the index is reached will the method and parameter start matching and
19 * If the index is never reached it will throw an exception in index.
21 * @since Class available since Release 1.0.0
23 class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation
28 protected $sequenceIndex;
33 protected $currentIndex = -1;
36 * @param int $sequenceIndex
38 public function __construct($sequenceIndex)
40 $this->sequenceIndex = $sequenceIndex;
46 public function toString()
48 return 'invoked at sequence index ' . $this->sequenceIndex;
52 * @param PHPUnit_Framework_MockObject_Invocation $invocation
55 public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
57 $this->currentIndex++;
59 return $this->currentIndex == $this->sequenceIndex;
63 * @param PHPUnit_Framework_MockObject_Invocation $invocation
65 public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation)
70 * Verifies that the current expectation is valid. If everything is OK the
71 * code should just return, if not it must throw an exception.
73 * @throws PHPUnit_Framework_ExpectationFailedException
75 public function verify()
77 if ($this->currentIndex < $this->sequenceIndex) {
78 throw new PHPUnit_Framework_ExpectationFailedException(
80 'The expected invocation at index %s was never reached.',