Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: namespace PHPUnit\Framework\MockObject\Matcher; Chris@14: Chris@14: use PHPUnit\Framework\ExpectationFailedException; Chris@14: Chris@14: /** Chris@14: * Invocation matcher which checks if a method has been invoked at least Chris@14: * N times. Chris@14: */ Chris@14: class InvokedAtLeastCount extends InvokedRecorder Chris@14: { Chris@14: /** Chris@14: * @var int Chris@14: */ Chris@14: private $requiredInvocations; Chris@14: Chris@14: /** Chris@14: * @param int $requiredInvocations Chris@14: */ Chris@14: public function __construct($requiredInvocations) Chris@14: { Chris@14: $this->requiredInvocations = $requiredInvocations; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return string Chris@14: */ Chris@14: public function toString() Chris@14: { Chris@14: return 'invoked at least ' . $this->requiredInvocations . ' times'; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Verifies that the current expectation is valid. If everything is OK the Chris@14: * code should just return, if not it must throw an exception. Chris@14: * Chris@14: * @throws ExpectationFailedException Chris@14: */ Chris@14: public function verify() Chris@14: { Chris@14: $count = $this->getInvocationCount(); Chris@14: Chris@14: if ($count < $this->requiredInvocations) { Chris@14: throw new ExpectationFailedException( Chris@14: 'Expected invocation at least ' . $this->requiredInvocations . Chris@14: ' times but it occurred ' . $count . ' time(s).' Chris@14: ); Chris@14: } Chris@14: } Chris@14: }