ReflectionParameter example



    public function testClosureCasterExcludingVerbosity()
    {
        $var = function D($a = 5) {};

        $this->assertDumpEquals('Closure&($a = 5) { …5}', $var, Caster::EXCLUDE_VERBOSE);
    }

    public function testReflectionParameter()
    {
        $var = new \ReflectionParameter(reflectionParameterFixture::class, 0);

        $this->assertDumpMatchesFormat(
            <<<'EOTXT' ReflectionParameter { +name: "arg1" position: 0 allowsNull: true typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass" } EOTXT
            , $var
        );

    public function testExceptionMessage(\ReflectionParameter $parameter, string $expectedMessage)
    {
        $exception = new InvalidParameterTypeException('my_service', 'int', $parameter);

        self::assertSame($expectedMessage$exception->getMessage());
    }

    public static function provideReflectionParameters(): iterable
    {
        yield 'static method' => [
            new \ReflectionParameter([MyClass::class, 'doSomething'], 0),
            'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\MyClass::doSomething()" accepts "array", "int" passed.',
        ];

        yield 'function' => [
            new \ReflectionParameter(__NAMESPACE__.'\\myFunction', 0),
            'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\myFunction()" accepts "array", "int" passed.',
        ];
    }
}

class MyClass
{
Home | Imprint | This part of the site doesn't use cookies.