Skip to content

Commit f3b65a6

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: fix merge [VarDumper] Test intl formatter broken since dumper does not replace the nnbsp character by standard space [WebProfilerBundle] Fix intercept external redirects [Webhook] Added missing XML attribute in config XSD [String] Skip a test when an issue is detected in PCRE2 [ExpressionLanguage] Fix null coalescing propagation [Mailer] Stop using the (local) AWS shared configuration in the PHPUnit tests. detect colors on not windows fix xterm detection refactor: hyper check Missing translations for Slovak (sk) #51954 Remove redundant PHPdoc line properly handle SYMFONY_DOTENV_VARS being the empty string Avoid incompatibility with symfony/console 7 bug #45057 [Messenger] Avoid reconnecting active Redis connections. [HttpKernel] Catch `TypeError` if the wrong type is used in `BackedEnumValueResolver` [Serializer] fix regression where nullable int cannot be serialized do not overwrite an application's default serialization context
2 parents 384186e + cc1b41e commit f3b65a6

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Controller/ArgumentResolver/BackedEnumValueResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
8686

8787
try {
8888
return [$enumType::from($value)];
89-
} catch (\ValueError $e) {
89+
} catch (\ValueError|\TypeError $e) {
9090
throw new NotFoundHttpException(sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType(), $argument->getName()).$e->getMessage(), $e);
9191
}
9292
}

Tests/Controller/ArgumentResolver/BackedEnumValueResolverTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\BackedEnumValueResolver;
1717
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1818
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19+
use Symfony\Component\HttpKernel\Tests\Fixtures\IntEnum;
1920
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2021

2122
class BackedEnumValueResolverTest extends TestCase
@@ -134,6 +135,18 @@ public function testResolveThrowsOnUnexpectedType()
134135
$resolver->resolve($request, $metadata);
135136
}
136137

138+
public function testResolveThrowsOnTypeError()
139+
{
140+
$resolver = new BackedEnumValueResolver();
141+
$request = self::createRequest(['suit' => 'value']);
142+
$metadata = self::createArgumentMetadata('suit', IntEnum::class);
143+
144+
$this->expectException(NotFoundHttpException::class);
145+
$this->expectExceptionMessage('Could not resolve the "Symfony\Component\HttpKernel\Tests\Fixtures\IntEnum $suit" controller argument: Symfony\Component\HttpKernel\Tests\Fixtures\IntEnum::from(): Argument #1 ($value) must be of type int, string given');
146+
147+
$resolver->resolve($request, $metadata);
148+
}
149+
137150
private static function createRequest(array $attributes = []): Request
138151
{
139152
return new Request([], [], $attributes);

Tests/Fixtures/IntEnum.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
13+
14+
enum IntEnum: int
15+
{
16+
case One = 1;
17+
case Two = 2;
18+
}

0 commit comments

Comments
 (0)