getPhpDoc( new ReflectionFunction( function (): EloquentBuilder { return $this; } ), $class ); $this->assertNotNull($phpdoc); $this->assertEquals( '@return \Illuminate\Database\Eloquent\Builder|static', $this->tagsToString($phpdoc, 'return') ); } protected function tagsToString(DocBlock $docBlock, string $name) { $tags = $docBlock->getTagsByName($name); $tags = array_map( function (Tag $tag) { return trim((string)$tag); }, $tags ); $tags = implode(PHP_EOL, $tags); return $tags; } } /** * @internal * @noinspection PhpMultipleClassesDeclarationsInOneFile */ class MacroMock extends Macro { public function __construct() { // no need to call parent } public function getPhpDoc(ReflectionFunctionAbstract $method, ReflectionClass $class = null): DocBlock { return (new Macro($method, '', $class ?? $method->getClosureScopeClass()))->phpdoc; } }