comparison vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtMostCount.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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
13 * N times.
14 *
15 * @since Class available since Release 2.2.0
16 */
17 class PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
18 {
19 /**
20 * @var int
21 */
22 private $allowedInvocations;
23
24 /**
25 * @param int $allowedInvocations
26 */
27 public function __construct($allowedInvocations)
28 {
29 $this->allowedInvocations = $allowedInvocations;
30 }
31
32 /**
33 * @return string
34 */
35 public function toString()
36 {
37 return 'invoked at most ' . $this->allowedInvocations . ' times';
38 }
39
40 /**
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.
43 *
44 * @throws PHPUnit_Framework_ExpectationFailedException
45 */
46 public function verify()
47 {
48 $count = $this->getInvocationCount();
49
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).'
54 );
55 }
56 }
57 }