Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
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
namespace PHPUnit\Framework\MockObject\Rule;
11
 
12
use PHPUnit\Framework\ExpectationFailedException;
13
use PHPUnit\Framework\MockObject\Invocation as BaseInvocation;
14
 
15
/**
16
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
17
 */
18
final class InvokedAtMostCount extends InvocationOrder
19
{
20
    /**
21
     * @var int
22
     */
23
    private $allowedInvocations;
24
 
25
    /**
26
     * @param int $allowedInvocations
27
     */
28
    public function __construct($allowedInvocations)
29
    {
30
        $this->allowedInvocations = $allowedInvocations;
31
    }
32
 
33
    public function toString(): string
34
    {
35
        return 'invoked at most ' . $this->allowedInvocations . ' times';
36
    }
37
 
38
    /**
39
     * Verifies that the current expectation is valid. If everything is OK the
40
     * code should just return, if not it must throw an exception.
41
     *
42
     * @throws ExpectationFailedException
43
     */
44
    public function verify(): void
45
    {
46
        $count = $this->getInvocationCount();
47
 
48
        if ($count > $this->allowedInvocations) {
49
            throw new ExpectationFailedException(
50
                'Expected invocation at most ' . $this->allowedInvocations .
51
                ' times but it occurred ' . $count . ' time(s).'
52
            );
53
        }
54
    }
55
 
56
    public function matches(BaseInvocation $invocation): bool
57
    {
58
        return true;
59
    }
60
 
61
    protected function invokedDo(BaseInvocation $invocation): void
62
    {
63
    }
64
}