method parameter default value rendering

This commit is contained in:
Gautier DELEGLISE
2024-10-26 23:49:53 +02:00
parent 60741fe387
commit fde2b5916d
2 changed files with 47 additions and 1 deletions
+39
View File
@@ -19,8 +19,10 @@ use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Boolean;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Float_;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Object_;
@@ -698,4 +700,41 @@ class MethodTest extends TestCase
$this->assertSame($description, $fixture->getDescription());
$this->assertTrue($fixture->returnsReference());
}
/**
* @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct
* @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue()
* @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
*
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
*/
public function testIfTagCanBeRenderedUsingMethodParameterWithDefaultValue(): void
{
$arguments = [
['name' => 'argument1', 'type' => new String_()],
['name' => 'argument2', 'type' => new Object_()],
];
$fixture = new Method(
'myMethod',
$arguments,
new Void_(),
false,
null,
false,
[
new MethodParameter('argument1', new String_(), false, false, '1'),
new MethodParameter('argument2', new Integer(), false, false, '1'),
new MethodParameter('argument3', new Boolean(), false, false, 'true'),
new MethodParameter('argument4', new Float_(), false, false, '1.23'),
]
);
$this->assertSame(
'@method void myMethod(string $argument1 = \'1\', int $argument2 = 1, bool $argument3 = true, float $argument4 = 1.23)',
$fixture->render()
);
}
}