Skip to content

Commit

Permalink
Merge pull request #427 from NiR-/fix-final-constructor
Browse files Browse the repository at this point in the history
Don't try to patch final constructors
  • Loading branch information
ciaranmcnulty authored Jun 13, 2019
2 parents 7e27218 + df60828 commit b789226
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function it_makes_all_constructor_arguments_optional(
ArgumentNode $arg1,
ArgumentNode $arg2
) {
$class->isExtendable('__construct')->willReturn(true);
$class->hasMethod('__construct')->willReturn(true);
$class->getMethod('__construct')->willReturn($method);
$method->getArguments()->willReturn(array($arg1, $arg2));
Expand All @@ -45,10 +46,18 @@ function it_makes_all_constructor_arguments_optional(

function it_creates_new_constructor_if_object_has_none(ClassNode $class)
{
$class->isExtendable('__construct')->willReturn(true);
$class->hasMethod('__construct')->willReturn(false);
$class->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))
->shouldBeCalled();

$this->apply($class);
}

function it_ignores_final_constructor(ClassNode $class)
{
$class->isExtendable('__construct')->willReturn(false);

$this->apply($class);
}
}
4 changes: 4 additions & 0 deletions src/Prophecy/Doubler/ClassPatch/DisableConstructorPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function supports(ClassNode $node)
*/
public function apply(ClassNode $node)
{
if (!$node->isExtendable('__construct')) {
return;
}

if (!$node->hasMethod('__construct')) {
$node->addMethod(new MethodNode('__construct', ''));

Expand Down

0 comments on commit b789226

Please sign in to comment.