8000 minor #39534 Normalize exceptions messages containing methods referen… · symfony/symfony@5eeb957 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5eeb957

Browse files
committed
minor #39534 Normalize exceptions messages containing methods references (ogizanagi)
This PR was merged into the 4.4 branch. Discussion ---------- Normalize exceptions messages containing methods references | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #39399 (comment) <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | N/A Normalizes across the codebase any exception message mentioning methods to contain a trailing `()` (Seems OK on 5.1 and 5.2 branch after this on is merged up) Commits ------- e2da2ac Normalize exceptions messages containing methods references
2 parents def8181 + e2da2ac commit 5eeb957

File tree

4 files changed

+24
-24
lines changed
  • src/Symfony/Component
    • DependencyInjection
      • < 8000 div id=":Rbartddab:" class="PRIVATE_TreeView-item-content prc-TreeView-TreeViewItemContent-f0r0b">Exception
  • Tests/Compiler
  • Serializer/Mapping/Loader
  • Validator/Mapping/Loader
  • 4 files changed

    +24
    -24
    lines changed

    src/Symfony/Component/DependencyInjection/Exception/InvalidParameterTypeException.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -25,6 +25,6 @@ public function __construct(string $serviceId, string $type, \ReflectionParamete
    2525
    $acceptedType = $acceptedType instanceof \ReflectionNamedType ? $acceptedType->getName 8000 () : (string) $acceptedType;
    2626
    $this->code = $type;
    2727

    28-
    parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $acceptedType, $type));
    28+
    parent::__construct(sprintf('Invalid definition for service "%s": argument %d of "%s::%s()" accepts "%s", "%s" passed.', $serviceId, 1 + $parameter->getPosition(), $parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $acceptedType, $type));
    2929
    }
    3030
    }

    src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeDeclarationsPassTest.php

    Lines changed: 19 additions & 19 deletions
    Original file line numberDiff line numberDiff line change
    @@ -40,7 +40,7 @@ class CheckTypeDeclarationsPassTest extends TestCase
    4040
    public function testProcessThrowsExceptionOnInvalidTypesConstructorArguments()
    4141
    {
    4242
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    43-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    43+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct()" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    4444

    4545
    $container = new ContainerBuilder();
    4646

    @@ -54,7 +54,7 @@ public function testProcessThrowsExceptionOnInvalidTypesConstructorArguments()
    5454
    public function testProcessThrowsExceptionOnInvalidTypesMethodCallArguments()
    5555
    {
    5656
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    57-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoo" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    57+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoo()" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    5858

    5959
    $container = new ContainerBuilder();
    6060

    @@ -68,7 +68,7 @@ public function testProcessThrowsExceptionOnInvalidTypesMethodCallArguments()
    6868
    public function testProcessFailsWhenPassingNullToRequiredArgument()
    6969
    {
    7070
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    71-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "NULL" passed.');
    71+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct()" accepts "stdClass", "NULL" passed.');
    7272

    7373
    $container = new ContainerBuilder();
    7474

    @@ -133,7 +133,7 @@ public function testProcessThrowsExceptionWhenMissingArgumentsInMethodCall()
    133133
    public function testProcessVariadicFails()
    134134
    {
    135135
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    136-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosVariadic" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    136+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosVariadic()" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    137137

    138138
    $container = new ContainerBuilder();
    139139

    @@ -152,7 +152,7 @@ public function testProcessVariadicFails()
    152152
    public function testProcessVariadicFailsOnPassingBadTypeOnAnotherArgument()
    153153
    {
    154154
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    155-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosVariadic" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    155+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosVariadic()" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    156156

    157157
    $container = new ContainerBuilder();
    158158

    @@ -216,7 +216,7 @@ public function testProcessSuccessWhenUsingOptionalArgumentWithGoodType()
    216216
    public function testProcessFailsWhenUsingOptionalArgumentWithBadType()
    217217
    {
    218218
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    219-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosOptional" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    219+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoosOptional()" accepts "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo", "stdClass" passed.');
    220220

    221221
    $container = new ContainerBuilder();
    222222

    @@ -246,7 +246,7 @@ public function testProcessSuccessWhenPassingNullToOptional()
    246246
    public function testProcessSuccessWhenPassingNullToOptionalThatDoesNotAcceptNull()
    247247
    {
    248248
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    249-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgumentNotNull::__construct" accepts "int", "NULL" passed.');
    249+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgumentNotNull::__construct()" accepts "int", "NULL" passed.');
    250250

    251251
    $container = new ContainerBuilder();
    252252

    @@ -259,7 +259,7 @@ public function testProcessSuccessWhenPassingNullToOptionalThatDoesNotAcceptNull
    259259
    public function testProcessFailsWhenPassingBadTypeToOptional()
    260260
    {
    261261
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    262-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgument::__construct" accepts "stdClass", "string" passed.');
    262+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarOptionalArgument::__construct()" accepts "stdClass", "string" passed.');
    263263

    264264
    $container = new ContainerBuilder();
    265265

    @@ -289,7 +289,7 @@ public function testProcessSuccessScalarType()
    289289
    public function testProcessFailsOnPassingScalarTypeToConstructorTypedWithClass()
    290290
    {
    291291
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    292-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct" accepts "stdClass", "integer" passed.');
    292+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Bar::__construct()" accepts "stdClass", "integer" passed.');
    293293

    294294
    $container = new ContainerBuilder();
    295295

    @@ -302,7 +302,7 @@ public function testProcessFailsOnPassingScalarTypeToConstructorTypedWithClass()
    302302
    public function testProcessFailsOnPassingScalarTypeToMethodTypedWithClass()
    303303
    {
    304304
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    305-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoo" accepts "stdClass", "string" passed.');
    305+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setFoo()" accepts "stdClass", "string" passed.');
    306306

    307307
    $container = new ContainerBuilder();
    308308

    @@ -317,7 +317,7 @@ public function testProcessFailsOnPassingScalarTypeToMethodTypedWithClass()
    317317
    public function testProcessFailsOnPassingClassToScalarTypedParameter()
    318318
    {
    319319
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    320-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setScalars" accepts "int", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    320+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setScalars()" accepts "int", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    321321

    322322
    $container = new ContainerBuilder();
    323323

    @@ -377,7 +377,7 @@ public function testProcessSuccessWhenPassingArray()
    377377
    public function testProcessSuccessWhenPassingIntegerToArrayTypedParameter()
    378378
    {
    379379
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException::class);
    380-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "integer" passed.');
    380+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray()" accepts "array", "integer" passed.');
    381381

    382382
    $container = new ContainerBuilder();
    383383

    @@ -437,7 +437,7 @@ public function testProcessFactory()
    437437
    public function testProcessFactoryFailsOnInvalidParameterType()
    438438
    {
    439439
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    440-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo::createBarArguments" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    440+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo::createBarArguments()" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    441441

    442442
    $container = new ContainerBuilder();
    443443

    @@ -455,7 +455,7 @@ public function testProcessFactoryFailsOnInvalidParameterType()
    455455
    public function testProcessFactoryFailsOnInvalidParameterTypeOptional()
    456456
    {
    457457
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    458-
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo::createBarArguments" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    458+
    $this->expectExceptionMessage('Invalid definition for service "bar": argument 2 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo::createBarArguments()" accepts "stdClass", "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\Foo" passed.');
    459459

    460460
    $container = new ContainerBuilder();
    461461

    @@ -601,7 +601,7 @@ public function testProcessDoesNotThrowsExceptionOnValidTypes()
    601601
    public function testProcessThrowsOnIterableTypeWhenScalarPassed()
    602602
    {
    603603
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    604-
    $this->expectExceptionMessage('Invalid definition for service "bar_call": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setIterable" accepts "iterable", "integer" passed.');
    604+
    $this->expectExceptionMessage('Invalid definition for service "bar_call": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\BarMethodCall::setIterable()" accepts "iterable", "integer" passed.');
    605605

    606606
    $container = new ContainerBuilder();
    607607

    @@ -645,7 +645,7 @@ public function testProcessSuccessWhenExpressionReturnsObject()
    645645
    public function testProcessHandleMixedEnvPlaceholder()
    646646
    {
    647647
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    648-
    $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "string" passed.');
    648+
    $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray()" accepts "array", "string" passed.');
    649649

    650650
    $container = new ContainerBuilder(new EnvPlaceholderParameterBag([
    651651
    'ccc' => '%env(FOO)%',
    @@ -661,7 +661,7 @@ public function testProcessHandleMixedEnvPlaceholder()
    661661
    public function testProcessHandleMultipleEnvPlaceholder()
    662662
    {
    663663
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    664-
    $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray" accepts "array", "string" passed.');
    664+
    $this->expectExceptionMessage('Invalid definition for service "foobar": argument 1 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarMethodCall::setArray()" accepts "array", "string" passed.');
    665665

    666666
    $container = new ContainerBuilder(new EnvPlaceholderParameterBag([
    667667
    'ccc' => '%env(FOO)%',
    @@ -848,7 +848,7 @@ public function testUnionTypeFailsWithReference()
    848848
    ->setArguments([new Reference('waldo')]);
    849849

    850850
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    851-
    $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.');
    851+
    $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.');
    852852

    853853
    (new CheckTypeDeclarationsPass(true))->process($container);
    854854

    @@ -866,7 +866,7 @@ public function testUnionTypeFailsWithBuiltin()
    866866
    ->setArguments([[1, 2, 3]]);
    867867

    868868
    $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
    869-
    $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.');
    869+
    $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct()" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.');
    870870

    871871
    (new CheckTypeDeclarationsPass(true))->process($container);
    872872

    0 commit comments

    Comments
     (0)
    0