/** * * @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); }
/** * @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); }
private function reflectArgumentToNode(ReflectionParameter $parameter, Node\MethodNode $methodNode) { $name = $parameter->getName() == '...' ? '__dot_dot_dot__' : $parameter->getName(); $node = new Node\ArgumentNode($name); $node->setTypeHint($this->getTypeHint($parameter)); if (true === $parameter->isDefaultValueAvailable()) { $node->setDefault($parameter->getDefaultValue()); } elseif (true === $parameter->isOptional() || true === $parameter->allowsNull()) { $node->setDefault(null); } if (true === $parameter->isPassedByReference()) { $node->setAsPassedByReference(); } $methodNode->addArgument($node); }
private function reflectArgumentToNode(ReflectionParameter $parameter, Node\MethodNode $methodNode) { $name = $parameter->getName() == '...' ? '__dot_dot_dot__' : $parameter->getName(); $node = new Node\ArgumentNode($name); $node->setTypeHint($this->getTypeHint($parameter)); if ($this->isVariadic($parameter)) { $node->setAsVariadic(); } if ($this->hasDefaultValue($parameter)) { $node->setDefault($this->getDefaultValue($parameter)); } if ($parameter->isPassedByReference()) { $node->setAsPassedByReference(); } $methodNode->addArgument($node); }