Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * This file is part of the PHPUnit_MockObject package.
|
Chris@0
|
4 *
|
Chris@0
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
6 *
|
Chris@0
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
8 * file that was distributed with this source code.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Invocation matcher which looks for a specific method name in the invocations.
|
Chris@0
|
13 *
|
Chris@0
|
14 * Checks the method name all incoming invocations, the name is checked against
|
Chris@0
|
15 * the defined constraint $constraint. If the constraint is met it will return
|
Chris@0
|
16 * true in matches().
|
Chris@0
|
17 *
|
Chris@0
|
18 * @since Class available since Release 1.0.0
|
Chris@0
|
19 */
|
Chris@0
|
20 class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
|
Chris@0
|
21 {
|
Chris@0
|
22 /**
|
Chris@0
|
23 * @var PHPUnit_Framework_Constraint
|
Chris@0
|
24 */
|
Chris@0
|
25 protected $constraint;
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * @param PHPUnit_Framework_Constraint|string
|
Chris@0
|
29 * @throws PHPUnit_Framework_Constraint
|
Chris@0
|
30 */
|
Chris@0
|
31 public function __construct($constraint)
|
Chris@0
|
32 {
|
Chris@0
|
33 if (!$constraint instanceof PHPUnit_Framework_Constraint) {
|
Chris@0
|
34 if (!is_string($constraint)) {
|
Chris@0
|
35 throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 $constraint = new PHPUnit_Framework_Constraint_IsEqual(
|
Chris@0
|
39 $constraint,
|
Chris@0
|
40 0,
|
Chris@0
|
41 10,
|
Chris@0
|
42 false,
|
Chris@0
|
43 true
|
Chris@0
|
44 );
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 $this->constraint = $constraint;
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * @return string
|
Chris@0
|
52 */
|
Chris@0
|
53 public function toString()
|
Chris@0
|
54 {
|
Chris@0
|
55 return 'method name ' . $this->constraint->toString();
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * @param PHPUnit_Framework_MockObject_Invocation $invocation
|
Chris@0
|
60 * @return bool
|
Chris@0
|
61 */
|
Chris@0
|
62 public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
|
Chris@0
|
63 {
|
Chris@0
|
64 return $this->constraint->evaluate($invocation->methodName, '', true);
|
Chris@0
|
65 }
|
Chris@0
|
66 }
|