Add typeless parameter support.

This commit is contained in:
Jaapio
2024-03-12 22:49:26 +01:00
parent 2b309a247d
commit 98566f2504
5 changed files with 78 additions and 14 deletions
@@ -16,6 +16,8 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tags\Param;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\String_;
final class ParamFactoryTest extends TagFactoryTestCase
@@ -24,23 +26,77 @@ final class ParamFactoryTest extends TagFactoryTestCase
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports
* @dataProvider paramInputProvider
*/
public function testParamIsCreated(): void
public function testParamIsCreated(string $input, Param $expected): void
{
$ast = $this->parseTag('@param string $var');
$ast = $this->parseTag($input);
$factory = new ParamFactory($this->giveTypeResolver(), $this->givenDescriptionFactory());
$context = new Context('global');
self::assertTrue($factory->supports($ast, $context));
self::assertEquals(
new Param(
'var',
new String_(),
false,
new Description(''),
false
),
$expected,
$factory->create($ast, $context)
);
}
/**
* @return array<array-key, string|Param>
*/
public function paramInputProvider(): array
{
return [
[
'@param string $var',
new Param(
'var',
new String_(),
false,
new Description(''),
false
),
],
[
'@param $param8 Description 4',
new Param(
'param8',
new Mixed_(),
false,
new Description('Description 4'),
false
),
],
[
'@param $param9',
new Param(
'param9',
new Mixed_(),
false,
new Description(''),
false
),
],
[
'@param int My Description',
new Param(
null,
new Integer(),
false,
new Description('My Description'),
false
),
],
[
'@param foo',
new Param(
null,
new Mixed_(),
false,
new Description(''),
false
),
],
];
}
}
@@ -45,7 +45,7 @@ abstract class TagFactoryTestCase extends TestCase
public function givenDescriptionFactory(): DescriptionFactory
{
$factory = m::mock(DescriptionFactory::class);
$factory->shouldReceive('create')->andReturn(new Description(''));
$factory->shouldReceive('create')->andReturnUsing(static fn ($args) => new Description($args));
return $factory;
}
@@ -25,7 +25,7 @@ final class VarFactoryTest extends TagFactoryTestCase
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::create
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::supports
*/
public function testParamIsCreated(): void
public function testVarIsCreated(): void
{
$ast = $this->parseTag('@var string $var');
$factory = new VarFactory($this->giveTypeResolver(), $this->givenDescriptionFactory());