From f2ef25bd4b29dd7f4aa73143881260e1054d37d3 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 7 Dec 2017 09:28:37 +0000 Subject: [PATCH 1/4] Hotfix: Optional nullable array parameter with not null default value --- src/Prophecy/Doubler/Generator/ClassMirror.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Prophecy/Doubler/Generator/ClassMirror.php b/src/Prophecy/Doubler/Generator/ClassMirror.php index 9f99239f6..c5f9a5c77 100644 --- a/src/Prophecy/Doubler/Generator/ClassMirror.php +++ b/src/Prophecy/Doubler/Generator/ClassMirror.php @@ -189,6 +189,8 @@ private function reflectArgumentToNode(ReflectionParameter $parameter, Node\Meth $node->setAsPassedByReference(); } + $node->setAsNullable($this->isNullable($parameter)); + $methodNode->addArgument($node); } From 7174e0a9f41780e710bab084b0b0b0ec485d6aa1 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 7 Dec 2017 10:05:43 +0000 Subject: [PATCH 2/4] Added test to prove fix "nullable array param with not null default value" --- fixtures/NullableArrayParameter.php | 10 ++++++++++ tests/Doubler/Generator/ClassMirrorTest.php | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 fixtures/NullableArrayParameter.php diff --git a/fixtures/NullableArrayParameter.php b/fixtures/NullableArrayParameter.php new file mode 100644 index 000000000..dae9239f6 --- /dev/null +++ b/fixtures/NullableArrayParameter.php @@ -0,0 +1,10 @@ +assertEquals('I\Simply\Am\Nonexistent', $arguments[0]->getTypeHint()); } + /** + * @test + */ + 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 */ From 3a47a1fad7fd9beccf514870d4ab2a459f702782 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 7 Dec 2017 10:06:08 +0000 Subject: [PATCH 3/4] Fixed expected calls in another test --- tests/Doubler/Generator/ClassMirrorTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doubler/Generator/ClassMirrorTest.php b/tests/Doubler/Generator/ClassMirrorTest.php index ef9bf4e4d..2457076e5 100644 --- a/tests/Doubler/Generator/ClassMirrorTest.php +++ b/tests/Doubler/Generator/ClassMirrorTest.php @@ -465,6 +465,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); From e485d91f7844c3e41d606e4ccb780baee2f61b77 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 7 Dec 2017 10:12:50 +0000 Subject: [PATCH 4/4] Added annotation to run test only on PHP 7.1+ --- tests/Doubler/Generator/ClassMirrorTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doubler/Generator/ClassMirrorTest.php b/tests/Doubler/Generator/ClassMirrorTest.php index 2457076e5..650255fec 100644 --- a/tests/Doubler/Generator/ClassMirrorTest.php +++ b/tests/Doubler/Generator/ClassMirrorTest.php @@ -409,6 +409,7 @@ public function it_doesnt_fail_to_typehint_nonexistent_FQCN() /** * @test + * @requires PHP 7.1 */ public function it_doesnt_fail_on_array_nullable_parameter_with_not_null_default_value() {