Skip to content

Commit

Permalink
Merge pull request phpspec#377 from webimpress/hotfix/368
Browse files Browse the repository at this point in the history
Hotfix phpspec#368: Optional nullable array parameter with not null default value
  • Loading branch information
ciaranmcnulty authored Aug 5, 2018
2 parents a180c32 + e485d91 commit 98892d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fixtures/NullableArrayParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Fixtures\Prophecy;

class NullableArrayParameter
{
public function iHaveNullableArrayParameterWithNotNullDefaultValue(?array $arr = array())
{
}
}
2 changes: 2 additions & 0 deletions src/Prophecy/Doubler/Generator/ClassMirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ private function reflectArgumentToNode(ReflectionParameter $parameter, Node\Meth
$node->setAsPassedByReference();
}

$node->setAsNullable($this->isNullable($parameter));

$methodNode->addArgument($node);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Doubler/Generator/ClassMirrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,21 @@ public function it_doesnt_fail_to_typehint_nonexistent_FQCN()
$this->assertEquals('I\Simply\Am\Nonexistent', $arguments[0]->getTypeHint());
}

/**
* @test
* @requires PHP 7.1
*/
public function it_doesnt_fail_on_array_nullable_parameter_with_not_null_default_value()
{
$mirror = new ClassMirror();

$classNode = $mirror->reflect(new \ReflectionClass('Fixtures\Prophecy\NullableArrayParameter'), array());
$method = $classNode->getMethod('iHaveNullableArrayParameterWithNotNullDefaultValue');
$arguments = $method->getArguments();
$this->assertSame('array', $arguments[0]->getTypeHint());
$this->assertTrue($arguments[0]->isNullable());
}

/**
* @test
*/
Expand Down Expand Up @@ -466,6 +481,7 @@ function it_changes_argument_names_if_they_are_varying()
$parameter->isDefaultValueAvailable()->willReturn(true);
$parameter->getDefaultValue()->willReturn(null);
$parameter->isPassedByReference()->willReturn(false);
$parameter->allowsNull()->willReturn(true);
$parameter->getClass()->willReturn($class);
if (version_compare(PHP_VERSION, '5.6', '>=')) {
$parameter->isVariadic()->willReturn(false);
Expand Down

0 comments on commit 98892d3

Please sign in to comment.