mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Allow for PhpDoc for macros with union types (#1148)
* Allow for PhpDoc for macros with union types * Replace null coalescing operator * Test init PhpDoc for macros with parameter union types * Allow for PhpDoc for macros with union return types * Add helper method to Macro class * Add changelog entry * Format * Complement changelog with PR link * Add missing return * Fix test for PHP < 8 * Rewrite PHP 8 test using eval() * Remove obsolete test class * Suppress Psalm errors for undefined ReflectionUnionType class * Remove unreachable return statement
This commit is contained in:
@@ -188,6 +188,29 @@ class MacroTest extends TestCase
|
||||
$this->assertEquals('@return \stdClass|null rrrrrrr', $this->tagsToString($phpdoc, 'return'));
|
||||
}
|
||||
|
||||
public function testInitPhpDocParamsWithUnionTypes(): void
|
||||
{
|
||||
if (PHP_VERSION_ID < 80000) {
|
||||
$this->markTestSkipped('This test requires PHP 8.0 or higher');
|
||||
}
|
||||
|
||||
$phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP'
|
||||
return new ReflectionFunction(
|
||||
/**
|
||||
* Test docblock.
|
||||
*/
|
||||
function (\Stringable|string $a = null): \Stringable|string|null {
|
||||
return $a;
|
||||
}
|
||||
);
|
||||
PHP));
|
||||
|
||||
$this->assertNotNull($phpdoc);
|
||||
$this->assertStringContainsString('Test docblock', $phpdoc->getText());
|
||||
$this->assertEquals('@param \Stringable|string|null $a', $this->tagsToString($phpdoc, 'param'));
|
||||
$this->assertEquals('@return \Stringable|string|null', $this->tagsToString($phpdoc, 'return'));
|
||||
}
|
||||
|
||||
protected function tagsToString(DocBlock $docBlock, string $name)
|
||||
{
|
||||
$tags = $docBlock->getTagsByName($name);
|
||||
|
||||
Reference in New Issue
Block a user