Valinor/tests/Unit/Definition/ParameterDefinitionTest.php
Romain Canon b6b3296638 feat: handle variadic parameters in constructors
Using variadic parameters is now handled properly by the library,
meaning the following example will run:

```php
final class SomeClass
{
    /** @var string[] */
    private array $values;

    public function __construct(string ...$values)
    {
        $this->values = $values;
    }
}

(new \CuyZ\Valinor\MapperBuilder())
    ->mapper()
    ->map(SomeClass::class, ['foo', 'bar', 'baz']);
```
2022-02-19 20:17:03 +01:00

43 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Unit\Definition;
use CuyZ\Valinor\Definition\ParameterDefinition;
use CuyZ\Valinor\Tests\Fake\Definition\FakeAttributes;
use CuyZ\Valinor\Tests\Fake\Type\FakeType;
use PHPUnit\Framework\TestCase;
final class ParameterDefinitionTest extends TestCase
{
public function test_parameter_data_can_be_retrieved(): void
{
$name = 'someParameter';
$signature = 'someParameterSignature';
$type = new FakeType();
$isOptional = true;
$isVariadic = true;
$defaultValue = 'Some parameter default value';
$attributes = new FakeAttributes();
$parameter = new ParameterDefinition(
$name,
$signature,
$type,
$isOptional,
$isVariadic,
$defaultValue,
$attributes
);
self::assertSame($name, $parameter->name());
self::assertSame($signature, $parameter->signature());
self::assertSame($type, $parameter->type());
self::assertSame($isOptional, $parameter->isOptional());
self::assertSame($isVariadic, $parameter->isVariadic());
self::assertSame($defaultValue, $parameter->defaultValue());
self::assertSame($attributes, $parameter->attributes());
}
}