comparison vendor/phpunit/phpunit-mock-objects/src/Matcher/MethodName.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the phpunit-mock-objects 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 namespace PHPUnit\Framework\MockObject\Matcher;
11
12 use PHPUnit\Framework\Constraint\Constraint;
13 use PHPUnit\Framework\Constraint\IsEqual;
14 use PHPUnit\Framework\MockObject\Invocation as BaseInvocation;
15 use PHPUnit\Util\InvalidArgumentHelper;
16
17 /**
18 * Invocation matcher which looks for a specific method name in the invocations.
19 *
20 * Checks the method name all incoming invocations, the name is checked against
21 * the defined constraint $constraint. If the constraint is met it will return
22 * true in matches().
23 */
24 class MethodName extends StatelessInvocation
25 {
26 /**
27 * @var Constraint
28 */
29 private $constraint;
30
31 /**
32 * @param Constraint|string
33 *
34 * @throws Constraint
35 * @throws \PHPUnit\Framework\Exception
36 */
37 public function __construct($constraint)
38 {
39 if (!$constraint instanceof Constraint) {
40 if (!\is_string($constraint)) {
41 throw InvalidArgumentHelper::factory(1, 'string');
42 }
43
44 $constraint = new IsEqual(
45 $constraint,
46 0,
47 10,
48 false,
49 true
50 );
51 }
52
53 $this->constraint = $constraint;
54 }
55
56 /**
57 * @return string
58 */
59 public function toString()
60 {
61 return 'method name ' . $this->constraint->toString();
62 }
63
64 /**
65 * @param BaseInvocation $invocation
66 *
67 * @return bool
68 */
69 public function matches(BaseInvocation $invocation)
70 {
71 return $this->constraint->evaluate($invocation->getMethodName(), '', true);
72 }
73 }