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 has been invoked at least
15 * @since Class available since Release 2.2.0
17 class PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
22 private $allowedInvocations;
25 * @param int $allowedInvocations
27 public function __construct($allowedInvocations)
29 $this->allowedInvocations = $allowedInvocations;
35 public function toString()
37 return 'invoked at most ' . $this->allowedInvocations . ' times';
41 * Verifies that the current expectation is valid. If everything is OK the
42 * code should just return, if not it must throw an exception.
44 * @throws PHPUnit_Framework_ExpectationFailedException
46 public function verify()
48 $count = $this->getInvocationCount();
50 if ($count > $this->allowedInvocations) {
51 throw new PHPUnit_Framework_ExpectationFailedException(
52 'Expected invocation at most ' . $this->allowedInvocations .
53 ' times but it occured ' . $count . ' time(s).'