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 function is_string;
13
use PHPUnit\Framework\Constraint\Constraint;
14
use PHPUnit\Framework\InvalidArgumentException;
15
use PHPUnit\Framework\MockObject\Invocation as BaseInvocation;
16
use PHPUnit\Framework\MockObject\MethodNameConstraint;
17
 
18
/**
19
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
20
 */
21
final class MethodName
22
{
23
    /**
24
     * @var Constraint
25
     */
26
    private $constraint;
27
 
28
    /**
29
     * @param Constraint|string $constraint
30
     *
31
     * @throws InvalidArgumentException
32
     */
33
    public function __construct($constraint)
34
    {
35
        if (is_string($constraint)) {
36
            $constraint = new MethodNameConstraint($constraint);
37
        }
38
 
39
        if (!$constraint instanceof Constraint) {
40
            throw InvalidArgumentException::create(1, 'PHPUnit\Framework\Constraint\Constraint object or string');
41
        }
42
 
43
        $this->constraint = $constraint;
44
    }
45
 
46
    public function toString(): string
47
    {
48
        return 'method name ' . $this->constraint->toString();
49
    }
50
 
51
    /**
52
     * @throws \PHPUnit\Framework\ExpectationFailedException
53
     * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
54
     */
55
    public function matches(BaseInvocation $invocation): bool
56
    {
57
        return $this->matchesName($invocation->getMethodName());
58
    }
59
 
60
    /**
61
     * @throws \PHPUnit\Framework\ExpectationFailedException
62
     * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
63
     */
64
    public function matchesName(string $methodName): bool
65
    {
66
        return (bool) $this->constraint->evaluate($methodName, '', true);
67
    }
68
}