class InvokedAtMostCount
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@internal This class is not covered by the backward compatibility promise for PHPUnit
Hierarchy
- class \PHPUnit\Framework\MockObject\Rule\InvocationOrder implements \PHPUnit\Framework\SelfDescribing
- class \PHPUnit\Framework\MockObject\Rule\InvokedAtMostCount extends \PHPUnit\Framework\MockObject\Rule\InvocationOrder
Expanded class hierarchy of InvokedAtMostCount
3 files declare their use of InvokedAtMostCount
- Functions.php in vendor/
phpunit/ phpunit/ src/ Framework/ Assert/ Functions.php - Matcher.php in vendor/
phpunit/ phpunit/ src/ Framework/ MockObject/ Runtime/ Matcher.php - TestCase.php in vendor/
phpunit/ phpunit/ src/ Framework/ TestCase.php
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ MockObject/ Runtime/ Rule/ InvokedAtMostCount.php, line 21
Namespace
PHPUnit\Framework\MockObject\RuleView source
final class InvokedAtMostCount extends InvocationOrder {
private readonly int $allowedInvocations;
public function __construct(int $allowedInvocations) {
$this->allowedInvocations = $allowedInvocations;
}
public function toString() : string {
return sprintf('invoked at most %d time%s', $this->allowedInvocations, $this->allowedInvocations !== 1 ? 's' : '');
}
/**
* Verifies that the current expectation is valid. If everything is OK the
* code should just return, if not it must throw an exception.
*
* @throws ExpectationFailedException
*/
public function verify() : void {
$actualInvocations = $this->numberOfInvocations();
if ($actualInvocations > $this->allowedInvocations) {
throw new ExpectationFailedException(sprintf('Expected invocation at most %d time%s but it occurred %d time%s.', $this->allowedInvocations, $this->allowedInvocations !== 1 ? 's' : '', $actualInvocations, $actualInvocations !== 1 ? 's' : ''));
}
}
public function matches(BaseInvocation $invocation) : bool {
return true;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
InvocationOrder::$invocations | private | property | @psalm-var list<BaseInvocation> | ||
InvocationOrder::hasBeenInvoked | public | function | |||
InvocationOrder::invoked | final public | function | |||
InvocationOrder::invokedDo | protected | function | 1 | ||
InvocationOrder::numberOfInvocations | public | function | |||
InvokedAtMostCount::$allowedInvocations | private | property | |||
InvokedAtMostCount::matches | public | function | Overrides InvocationOrder::matches | ||
InvokedAtMostCount::toString | public | function | Returns a string representation of the object. | Overrides SelfDescribing::toString | |
InvokedAtMostCount::verify | public | function | Verifies that the current expectation is valid. If everything is OK the code should just return, if not it must throw an exception. |
Overrides InvocationOrder::verify | |
InvokedAtMostCount::__construct | public | function |