1<?php 2/* 3 * This file is part of the PHPUnit_MockObject package. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11/** 12 * Invocation matcher which checks if a method has been invoked at least one 13 * time. 14 * 15 * If the number of invocations is 0 it will throw an exception in verify. 16 * 17 * @since Class available since Release 1.0.0 18 */ 19class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder 20{ 21 /** 22 * @return string 23 */ 24 public function toString() 25 { 26 return 'invoked at least once'; 27 } 28 29 /** 30 * Verifies that the current expectation is valid. If everything is OK the 31 * code should just return, if not it must throw an exception. 32 * 33 * @throws PHPUnit_Framework_ExpectationFailedException 34 */ 35 public function verify() 36 { 37 $count = $this->getInvocationCount(); 38 39 if ($count < 1) { 40 throw new PHPUnit_Framework_ExpectationFailedException( 41 'Expected invocation at least once but it never occurred.' 42 ); 43 } 44 } 45} 46