Skip to content

Commit

Permalink
Fix type hints in the generator to return an absolute class name. Thi…
Browse files Browse the repository at this point in the history
…s fixes a bug with namespaces.
  • Loading branch information
afilina committed Feb 26, 2019
1 parent be9bf28 commit 36fe152
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Mockery/Generator/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tests/Mockery/Generator/ParameterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Mockery\Generator;
{
class ParameterTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldBringIteratorAggregateToHeadOfTargetListIfTraversablePresent()
{
$rfp = new \ReflectionParameter(array('\TestSubjectNameSpace\TestSubject', 'foo'), 0);
$parameterGenerator = new Parameter($rfp);
$typeHint = $parameterGenerator->getTypeHintAsString();

$this->assertEquals('\TypeHintNameSpace\TypeHint', $typeHint);
}
}
}

namespace TypeHintNameSpace;
{
class TypeHint
{
}
}

namespace TestSubjectNameSpace;
use TypeHintNameSpace\TypeHint;
{
class TestSubject
{
public function foo(TypeHint $param)
{
}
}
}


0 comments on commit 36fe152

Please sign in to comment.