Skip to content

Commit e56b079

Browse files
authored
Merge pull request #50 from facile-it/feature/reference
Support methods returning a reference
2 parents da80602 + 62f983a commit e56b079

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/Generator/Template/MethodTemplate.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MethodTemplate implements TemplateInterface
1414
use VisibilityTrait;
1515

1616
private const TEMPLATE = '
17-
%s %s function %s(%s)%s
17+
%s %s function %s %s(%s)%s
1818
{
1919
%s $this->__call("%s", func_get_args());
2020
}
@@ -42,6 +42,7 @@ protected static function doGenerate(\ReflectionMethod $method): string
4242
$visibility = static::getVisibility($method);
4343

4444
$static = $method->isStatic() ? 'static' : '';
45+
$reference = $method->returnsReference() ? '&' : '';
4546

4647
$parameters = $method->getParameters();
4748
$parametersCode = [];
@@ -66,6 +67,7 @@ protected static function doGenerate(\ReflectionMethod $method): string
6667
self::TEMPLATE,
6768
$visibility,
6869
$static,
70+
$reference,
6971
$methodName,
7072
implode(',', $parametersCode),
7173
$returnType,

src/Tests/IncompleteAbstractTestClass.php

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function getCallable(): callable
3636
};
3737
}
3838

39+
public function & getReference(): array
40+
{
41+
return [];
42+
}
43+
3944
public function withArgument(int $argument): int
4045
{
4146
return $argument;

src/Tests/MokaMockingStrategyTestCase.php

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected function setUp(): void
4040
'$private' => mt_rand(),
4141
'isTrue' => (bool)random_int(0, 1),
4242
'getInt' => mt_rand(),
43+
'getReference' => [],
4344
'withArgument' => mt_rand(),
4445
'throwException' => new \Exception((string)mt_rand())
4546
];

tests/Generator/Template/MethodTemplateTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function testGenerate()
1515
new \ReflectionMethod(FooTestClass::class, 'getCallable')
1616
);
1717

18-
$this->assertRegExp('/public +function getCallable\(/', $code);
18+
$this->assertRegExp('/public +function +getCallable\(/', $code);
1919
}
2020
}

0 commit comments

Comments
 (0)