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 */
17class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder
18{
19    /**
20     * @var int
21     */
22    private $requiredInvocations;
23
24    /**
25     * @param int $requiredInvocations
26     */
27    public function __construct($requiredInvocations)
28    {
29        $this->requiredInvocations = $requiredInvocations;
30    }
31
32    /**
33     * @return string
34     */
35    public function toString()
36    {
37        return 'invoked at least ' . $this->requiredInvocations . ' 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->requiredInvocations) {
51            throw new PHPUnit_Framework_ExpectationFailedException(
52                'Expected invocation at least ' . $this->requiredInvocations .
53                ' times but it occurred ' . $count . ' time(s).'
54            );
55        }
56    }
57}
58