/** * @param \Prophecy\Doubler\Generator\Node\ClassNode $class * @param \Prophecy\Doubler\Generator\Node\MethodNode $method * @param \Prophecy\Doubler\Generator\Node\ArgumentNode $argument */ function it_overrides_properly_methods_with_args_passed_by_reference($class, $method, $argument) { $class->getParentClass()->willReturn('RuntimeException'); $class->getInterfaces()->willReturn(array('Prophecy\\Doubler\\Generator\\MirroredInterface')); $class->getProperties()->willReturn(array()); $class->getMethods()->willReturn(array($method)); $method->getName()->willReturn('getName'); $method->getVisibility()->willReturn('public'); $method->isStatic()->willReturn(false); $method->getArguments()->willReturn(array($argument)); $method->getCode()->willReturn('return $this->name;'); $argument->getName()->willReturn('fullname'); $argument->getTypeHint()->willReturn('array'); $argument->isOptional()->willReturn(true); $argument->getDefault()->willReturn(null); $argument->isPassedByReference()->willReturn(true); $code = $this->generate('CustomClass', $class); $expected = <<<'PHP' namespace { class CustomClass extends \RuntimeException implements \Prophecy\Doubler\Generator\MirroredInterface { public function getName(array &$fullname = NULL) { return $this->name; } } } PHP; $expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n")); $code->shouldBe($expected); }
function it_will_remove_echo_and_eval_methods(ClassNode $node, MethodNode $method1, MethodNode $method2, MethodNode $method3) { $node->removeMethod('eval')->shouldBeCalled(); $node->removeMethod('echo')->shouldBeCalled(); $method1->getName()->willReturn('echo'); $method2->getName()->willReturn('eval'); $method3->getName()->willReturn('notKeyword'); $node->getMethods()->willReturn(array('echo' => $method1, 'eval' => $method2, 'notKeyword' => $method3)); $this->apply($node); }
/** * @param \Prophecy\Doubler\Generator\Node\ClassNode $node * @param \Prophecy\Doubler\Generator\Node\MethodNode $constructor * @param \Prophecy\Doubler\Generator\Node\MethodNode $method1 * @param \Prophecy\Doubler\Generator\Node\MethodNode $method2 * @param \Prophecy\Doubler\Generator\Node\MethodNode $method3 */ function it_forces_all_class_methods_except_constructor_to_proxy_calls_into_prophecy_makeCall($node, $constructor, $method1, $method2, $method3) { $node->addInterface('Prophecy\\Prophecy\\ProphecySubjectInterface')->willReturn(NULL); $node->addProperty('objectProphecy', 'private')->willReturn(NULL); $node->hasMethod(Argument::any())->willReturn(FALSE); $node->addMethod(Argument::type('Prophecy\\Doubler\\Generator\\Node\\MethodNode'))->willReturn(NULL); $node->addMethod(Argument::type('Prophecy\\Doubler\\Generator\\Node\\MethodNode'))->willReturn(NULL); $constructor->getName()->willReturn('__construct'); $method1->getName()->willReturn('method1'); $method2->getName()->willReturn('method2'); $method3->getName()->willReturn('method3'); $node->getMethods()->willReturn(array('method1' => $method1, 'method2' => $method2, 'method3' => $method3)); $constructor->setCode(Argument::any())->shouldNotBeCalled(); $method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled(); $method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled(); $method3->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')->shouldBeCalled(); $this->apply($node); }
public function addMethod(MethodNode $method) { $this->methods[$method->getName()] = $method; }
public function addMethod(MethodNode $method) { if (!$this->isExtendable($method->getName())) { $message = sprintf('Method `%s` is not extendable, so can not be added.', $method->getName()); throw new MethodNotExtendableException($message, $this->getParentClass(), $method->getName()); } $this->methods[$method->getName()] = $method; }
/** * * @param \Prophecy\Doubler\Generator\Node\MethodNode $method */ function its_hasMethod_returns_false_if_method_has_been_removed($method) { $method->getName()->willReturn('getName'); $this->addMethod($method); $this->removeMethod('getName'); $this->hasMethod('getName')->shouldReturn(false); }
function it_throws_an_exception_when_adding_a_method_that_isnt_extendable(MethodNode $method) { $this->addUnextendableMethod('testMethod'); $method->getName()->willReturn('testMethod'); $expectedException = new MethodNotExtendableException("Method `testMethod` is not extendable, so can not be added.", "stdClass", "testMethod"); $this->shouldThrow($expectedException)->duringAddMethod($method); }