Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Invocation matcher which checks if a method was invoked at a certain index. Chris@0: * Chris@0: * If the expected index number does not match the current invocation index it Chris@0: * will not match which means it skips all method and parameter matching. Only Chris@0: * once the index is reached will the method and parameter start matching and Chris@0: * verifying. Chris@0: * Chris@0: * If the index is never reached it will throw an exception in index. Chris@0: * Chris@0: * @since Class available since Release 1.0.0 Chris@0: */ Chris@0: class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation Chris@0: { Chris@0: /** Chris@0: * @var int Chris@0: */ Chris@0: protected $sequenceIndex; Chris@0: Chris@0: /** Chris@0: * @var int Chris@0: */ Chris@0: protected $currentIndex = -1; Chris@0: Chris@0: /** Chris@0: * @param int $sequenceIndex Chris@0: */ Chris@0: public function __construct($sequenceIndex) Chris@0: { Chris@0: $this->sequenceIndex = $sequenceIndex; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function toString() Chris@0: { Chris@0: return 'invoked at sequence index ' . $this->sequenceIndex; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param PHPUnit_Framework_MockObject_Invocation $invocation Chris@0: * @return bool Chris@0: */ Chris@0: public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) Chris@0: { Chris@0: $this->currentIndex++; Chris@0: Chris@0: return $this->currentIndex == $this->sequenceIndex; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @param PHPUnit_Framework_MockObject_Invocation $invocation Chris@0: */ Chris@0: public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) Chris@0: { Chris@0: } Chris@0: Chris@0: /** Chris@0: * Verifies that the current expectation is valid. If everything is OK the Chris@0: * code should just return, if not it must throw an exception. Chris@0: * Chris@0: * @throws PHPUnit_Framework_ExpectationFailedException Chris@0: */ Chris@0: public function verify() Chris@0: { Chris@0: if ($this->currentIndex < $this->sequenceIndex) { Chris@0: throw new PHPUnit_Framework_ExpectationFailedException( Chris@0: sprintf( Chris@0: 'The expected invocation at index %s was never reached.', Chris@0: $this->sequenceIndex Chris@0: ) Chris@0: ); Chris@0: } Chris@0: } Chris@0: }