Skip to content

Commit

Permalink
Add regression test for phpspec#568
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Jan 24, 2024
1 parent d4f454f commit 3e7dd4b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3e7dd4b

Please sign in to comment.