From 36fe152e3c8b82a91f01cad4b82e93bdd59e8a3d Mon Sep 17 00:00:00 2001 From: Anna Filina Date: Tue, 26 Feb 2019 14:31:03 -0500 Subject: [PATCH 1/2] Fix type hints in the generator to return an absolute class name. This fixes a bug with namespaces. --- library/Mockery/Generator/Parameter.php | 2 +- tests/Mockery/Generator/ParameterTest.php | 39 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/Mockery/Generator/ParameterTest.php diff --git a/library/Mockery/Generator/Parameter.php b/library/Mockery/Generator/Parameter.php index 4e08710b4..ecbc81991 100644 --- a/library/Mockery/Generator/Parameter.php +++ b/library/Mockery/Generator/Parameter.php @@ -48,7 +48,7 @@ public function getTypeHintAsString() if ((version_compare(PHP_VERSION, '5.4.1') >= 0)) { try { if ($this->rfp->getClass()) { - return $this->getOptionalSign() . $this->rfp->getClass()->getName(); + return $this->getOptionalSign() . '\\' . $this->rfp->getClass()->getName(); } } catch (\ReflectionException $re) { // noop diff --git a/tests/Mockery/Generator/ParameterTest.php b/tests/Mockery/Generator/ParameterTest.php new file mode 100644 index 000000000..fcd3627af --- /dev/null +++ b/tests/Mockery/Generator/ParameterTest.php @@ -0,0 +1,39 @@ +getTypeHintAsString(); + + $this->assertEquals('\TypeHintNameSpace\TypeHint', $typeHint); + } + } +} + +namespace TypeHintNameSpace; +{ + class TypeHint + { + } +} + +namespace TestSubjectNameSpace; +use TypeHintNameSpace\TypeHint; +{ + class TestSubject + { + public function foo(TypeHint $param) + { + } + } +} + + From 3629dcb550cc5d9ead1f9b8634c619138db29a81 Mon Sep 17 00:00:00 2001 From: Anna Filina Date: Tue, 26 Feb 2019 14:39:53 -0500 Subject: [PATCH 2/2] Rename copy-pasta test name. --- tests/Mockery/Generator/ParameterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mockery/Generator/ParameterTest.php b/tests/Mockery/Generator/ParameterTest.php index fcd3627af..17dc5ab13 100644 --- a/tests/Mockery/Generator/ParameterTest.php +++ b/tests/Mockery/Generator/ParameterTest.php @@ -7,7 +7,7 @@ class ParameterTest extends \PHPUnit_Framework_TestCase /** * @test */ - public function shouldBringIteratorAggregateToHeadOfTargetListIfTraversablePresent() + public function shouldReturnAbsoluteHintPathIfNamespaceProvided() { $rfp = new \ReflectionParameter(array('\TestSubjectNameSpace\TestSubject', 'foo'), 0); $parameterGenerator = new Parameter($rfp);