本文整理汇总了PHP中Prophecy\Doubler\Generator\Node\ClassNode::getMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassNode::getMethod方法的具体用法?PHP ClassNode::getMethod怎么用?PHP ClassNode::getMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Prophecy\Doubler\Generator\Node\ClassNode
的用法示例。
在下文中一共展示了ClassNode::getMethod方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
/**
* Removes special exception static methods from the doubled methods.
*
* @param ClassNode $node
*
* @return void
*/
public function apply(ClassNode $node)
{
if ($node->hasMethod('setTraceOptions')) {
$node->getMethod('setTraceOptions')->useParentCode();
}
if ($node->hasMethod('getTraceOptions')) {
$node->getMethod('getTraceOptions')->useParentCode();
}
}
示例2:
/**
* @param \Prophecy\Doubler\Generator\Node\ClassNode $node
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
* @param \Prophecy\Doubler\Generator\Node\MethodNode $getterMethod
*/
function it_uses_parent_code_for_setTraceOptions($node, $method, $getterMethod)
{
$node->hasMethod('setTraceOptions')->willReturn(TRUE);
$node->getMethod('setTraceOptions')->willReturn($method);
$node->hasMethod('getTraceOptions')->willReturn(TRUE);
$node->getMethod('getTraceOptions')->willReturn($getterMethod);
$method->useParentCode()->shouldBeCalled();
$getterMethod->useParentCode()->shouldBeCalled();
$this->apply($node);
}
示例3:
/**
* @param \Prophecy\Doubler\Generator\Node\ClassNode $node
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
*/
function it_updates_existing_method_if_found($node, $method)
{
$node->hasMethod('__construct')->willReturn(true);
$node->getMethod('__construct')->willReturn($method);
$method->setCode(Argument::any())->shouldBeCalled();
$this->apply($node);
}
示例4:
/**
*
* @param \Prophecy\Doubler\Generator\Node\ClassNode $class
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg1
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg2
*/
function it_makes_all_newInstance_arguments_optional($class, $method, $arg1, $arg2)
{
$class->getMethod('newInstance')->willReturn($method);
$method->getArguments()->willReturn(array($arg1));
$arg1->setDefault(null)->shouldBeCalled();
$this->apply($class);
}
示例5: apply
/**
* Apply Prophecy functionality to class node.
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
$node->addInterface('Prophecy\\Prophecy\\ProphecySubjectInterface');
$node->addProperty('objectProphecy', 'private');
foreach ($node->getMethods() as $name => $method) {
if ('__construct' === strtolower($name)) {
continue;
}
$method->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());');
}
$prophecySetter = new MethodNode('setProphecy');
$prophecyArgument = new ArgumentNode('prophecy');
$prophecyArgument->setTypeHint('Prophecy\\Prophecy\\ProphecyInterface');
$prophecySetter->addArgument($prophecyArgument);
$prophecySetter->setCode('$this->objectProphecy = $prophecy;');
$prophecyGetter = new MethodNode('getProphecy');
$prophecyGetter->setCode('return $this->objectProphecy;');
if ($node->hasMethod('__call')) {
$__call = $node->getMethod('__call');
} else {
$__call = new MethodNode('__call');
$__call->addArgument(new ArgumentNode('name'));
$__call->addArgument(new ArgumentNode('arguments'));
$node->addMethod($__call);
}
$__call->setCode(<<<PHP
throw new \\Prophecy\\Exception\\Doubler\\MethodNotFoundException(
sprintf('Method `%s::%s()` not found.', get_class(\$this), func_get_arg(0)),
\$this->getProphecy(), func_get_arg(0)
);
PHP
);
$node->addMethod($prophecySetter);
$node->addMethod($prophecyGetter);
}
示例6:
/**
* @param \Prophecy\Doubler\Generator\Node\ClassNode $class
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg1
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg2
*/
function it_makes_all_constructor_arguments_optional($class, $method, $arg1, $arg2)
{
$class->hasMethod('__construct')->willReturn(true);
$class->getMethod('__construct')->willReturn($method);
$method->getArguments()->willReturn(array($arg1, $arg2));
$arg1->setDefault(null)->shouldBeCalled();
$arg2->setDefault(null)->shouldBeCalled();
$method->setCode(Argument::type('string'))->shouldBeCalled();
$this->apply($class);
}
示例7: strpos
/**
* @param \Prophecy\Doubler\Generator\Node\ClassNode $node
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
*/
function it_should_not_supply_a_file_for_a_directory_iterator($node, $method)
{
$node->hasMethod('__construct')->willReturn(true);
$node->getMethod('__construct')->willReturn($method);
$node->getParentClass()->willReturn('DirectoryIterator');
$method->setCode(Argument::that(function ($value) {
return strpos($value, '.php') === false;
}))->shouldBeCalled();
$this->apply($node);
}
示例8: apply
/**
* Updated constructor code to call parent one with dummy file argument.
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
if ($node->hasMethod('__construct')) {
$constructor = $node->getMethod('__construct');
} else {
$constructor = new MethodNode('__construct');
$node->addMethod($constructor);
}
$constructor->setCode('return parent::__construct("' . __FILE__ . '");');
}
示例9: strpos
function it_should_supply_a_file_for_a_spl_file_object(ClassNode $node, MethodNode $method)
{
$node->hasMethod('__construct')->willReturn(true);
$node->getMethod('__construct')->willReturn($method);
$node->getParentClass()->willReturn('SplFileObject');
$method->setCode(Argument::that(function ($value) {
return strpos($value, '.php') !== false;
}))->shouldBeCalled();
$this->apply($node);
}
示例10: apply
/**
* Updated constructor code to call parent one with dummy file argument.
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
if ($node->hasMethod('__construct')) {
$constructor = $node->getMethod('__construct');
} else {
$constructor = new MethodNode('__construct');
$node->addMethod($constructor);
}
if ($this->nodeIsDirectoryIterator($node)) {
$constructor->setCode('return parent::__construct("' . __DIR__ . '");');
return;
}
$constructor->useParentCode();
}
示例11: apply
/**
* Makes all class constructor arguments optional.
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
if (!$node->hasMethod('__construct')) {
$node->addMethod(new MethodNode('__construct', ''));
return;
}
$constructor = $node->getMethod('__construct');
foreach ($constructor->getArguments() as $argument) {
$argument->setDefault(null);
}
$constructor->setCode(<<<PHP
if (0 < func_num_args()) {
call_user_func_array(array('parent', '__construct'), func_get_args());
}
PHP
);
}
示例12: apply
/**
* Updates newInstance's first argument to make it optional
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
foreach ($node->getMethod('newInstance')->getArguments() as $argument) {
$argument->setDefault(null);
}
}