Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: namespace PHPUnit\Framework\MockObject\Matcher; Chris@14: Chris@14: use PHPUnit\Framework\Constraint\Constraint; Chris@14: use PHPUnit\Framework\Constraint\IsEqual; Chris@14: use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; Chris@14: use PHPUnit\Util\InvalidArgumentHelper; Chris@14: Chris@14: /** Chris@14: * Invocation matcher which looks for a specific method name in the invocations. Chris@14: * Chris@14: * Checks the method name all incoming invocations, the name is checked against Chris@14: * the defined constraint $constraint. If the constraint is met it will return Chris@14: * true in matches(). Chris@14: */ Chris@14: class MethodName extends StatelessInvocation Chris@14: { Chris@14: /** Chris@14: * @var Constraint Chris@14: */ Chris@14: private $constraint; Chris@14: Chris@14: /** Chris@14: * @param Constraint|string Chris@14: * Chris@14: * @throws Constraint Chris@14: * @throws \PHPUnit\Framework\Exception Chris@14: */ Chris@14: public function __construct($constraint) Chris@14: { Chris@14: if (!$constraint instanceof Constraint) { Chris@14: if (!\is_string($constraint)) { Chris@14: throw InvalidArgumentHelper::factory(1, 'string'); Chris@14: } Chris@14: Chris@14: $constraint = new IsEqual( Chris@14: $constraint, Chris@14: 0, Chris@14: 10, Chris@14: false, Chris@14: true Chris@14: ); Chris@14: } Chris@14: Chris@14: $this->constraint = $constraint; Chris@14: } Chris@14: Chris@14: /** Chris@14: * @return string Chris@14: */ Chris@14: public function toString() Chris@14: { Chris@14: return 'method name ' . $this->constraint->toString(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * @param BaseInvocation $invocation Chris@14: * Chris@14: * @return bool Chris@14: */ Chris@14: public function matches(BaseInvocation $invocation) Chris@14: { Chris@14: return $this->constraint->evaluate($invocation->getMethodName(), '', true); Chris@14: } Chris@14: }