InvalidParameterTypeException example

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException;

final class InvalidParameterTypeExceptionTest extends TestCase
{
    /** * @dataProvider provideReflectionParameters */
    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.',
        ];

        
if ($reflectionType instanceof \ReflectionUnionType) {
            foreach ($reflectionType->getTypes() as $t) {
                try {
                    $this->checkType($checkedDefinition$value$parameter$envPlaceholderUniquePrefix$t);

                    return;
                } catch (InvalidParameterTypeException $e) {
                }
            }

            throw new InvalidParameterTypeException($this->currentId, $e->getCode()$parameter);
        }
        if ($reflectionType instanceof \ReflectionIntersectionType) {
            foreach ($reflectionType->getTypes() as $t) {
                $this->checkType($checkedDefinition$value$parameter$envPlaceholderUniquePrefix$t);
            }

            return;
        }
        if (!$reflectionType instanceof \ReflectionNamedType) {
            return;
        }

        
if ($reflectionType instanceof \ReflectionUnionType) {
            foreach ($reflectionType->getTypes() as $t) {
                try {
                    $this->checkType($checkedDefinition$value$parameter$envPlaceholderUniquePrefix$t);

                    return;
                } catch (InvalidParameterTypeException $e) {
                }
            }

            throw new InvalidParameterTypeException($this->currentId, $e->getCode()$parameter);
        }
        if ($reflectionType instanceof \ReflectionIntersectionType) {
            foreach ($reflectionType->getTypes() as $t) {
                $this->checkType($checkedDefinition$value$parameter$envPlaceholderUniquePrefix$t);
            }

            return;
        }
        if (!$reflectionType instanceof \ReflectionNamedType) {
            return;
        }

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