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 one Chris@14: * time. Chris@14: * Chris@14: * If the number of invocations is 0 it will throw an exception in verify. Chris@14: */ Chris@14: class InvokedAtLeastOnce extends InvokedRecorder Chris@14: { Chris@14: /** Chris@14: * @return string Chris@14: */ Chris@14: public function toString() Chris@14: { Chris@14: return 'invoked at least once'; 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 < 1) { Chris@14: throw new ExpectationFailedException( Chris@14: 'Expected invocation at least once but it never occurred.' Chris@14: ); Chris@14: } Chris@14: } Chris@14: }