From 3e7dd4bf234772285f698eade7179846a7565bee Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 24 Jan 2024 18:16:38 +0100 Subject: [PATCH] Add regression test for #568 --- .../Generator/ClassCodeGeneratorSpec.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php b/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php index 50fb1704c..dad9423b1 100644 --- a/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php +++ b/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php @@ -422,6 +422,46 @@ function it_generates_read_only_class_if_parent_class_is_read_only(ClassNode $cl readonly class CustomClass extends \ReadOnlyClass implements \Prophecy\Doubler\Generator\MirroredInterface { +} +} +PHP; + $expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n")); + $code->shouldBe($expected); + } + + function it_generates_correct_code_if_argument_default_value_is_an_object( + ClassNode $class, + MethodNode $method, + ArgumentNode $argument + ) { + $class->getParentClass()->willReturn('ClassWithArgument'); + $class->getInterfaces()->willReturn(array('Prophecy\Doubler\Generator\MirroredInterface')); + $class->getProperties()->willReturn(array()); + $class->getMethods()->willReturn(array($method)); + $class->isReadOnly()->willReturn(false); + + $method->getName()->willReturn('foo'); + $method->getVisibility()->willReturn('public'); + $method->isStatic()->willReturn(false); + $method->getArguments()->willReturn([$argument]); + $method->getReturnTypeNode()->willReturn(new ReturnTypeNode()); + $method->returnsReference()->willReturn(false); + $method->getCode()->willReturn(''); + + $argument->getTypeNode()->willReturn(new ArgumentTypeNode(\DateTimeInterface::class)); + $argument->getName()->willReturn('arg'); + $argument->isPassedByReference()->willReturn(false); + $argument->isVariadic()->willReturn(false); + $argument->isOptional()->willReturn(true); + $argument->getDefault()->willReturn(new \DateTime()); + + $code = $this->generate('CustomClass', $class); + $expected =<<<'PHP' +namespace { +class CustomClass extends \ClassWithArgument implements \Prophecy\Doubler\Generator\MirroredInterface { +public function foo(\DateTimeInterface $arg = NULL) { + +} } } PHP;