|
18 | 18 | use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
|
19 | 19 | use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
|
20 | 20 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
| 21 | +use Symfony\Component\HttpKernel\Tests\Fixtures\Suit; |
21 | 22 |
|
22 | 23 | class QueryParameterValueResolverTest extends TestCase
|
23 | 24 | {
|
@@ -176,6 +177,33 @@ public static function provideTestResolve(): iterable
|
176 | 177 | 'Invalid query parameter "isVerified".',
|
177 | 178 | ];
|
178 | 179 |
|
| 180 | + yield 'parameter found and backing value' => [ |
| 181 | + Request::create('/', 'GET', ['suit' => 'H']), |
| 182 | + new ArgumentMetadata('suit', Suit::class, false, false, false, attributes: [new MapQueryParameter()]), |
| 183 | + [Suit::Hearts], |
| 184 | + null, |
| 185 | + ]; |
| 186 | + yield 'parameter found and backing value variadic' => [ |
| 187 | + Request::create('/', 'GET', ['suit' => ['H', 'D']]), |
| 188 | + new ArgumentMetadata('suit', Suit::class, true, false, false, attributes: [new MapQueryParameter()]), |
| 189 | + [Suit::Hearts, Suit::Diamonds], |
| 190 | + null, |
| 191 | + ]; |
| 192 | + yield 'parameter found and backing type not int nor string' => [ |
| 193 | + Request::create('/', 'GET', ['suit' => 1]), |
| 194 | + new ArgumentMetadata('suit', Suit::class, false, false, false, attributes: [new MapQueryParameter(filter: \FILTER_VALIDATE_BOOL)]), |
| 195 | + [], |
| 196 | + NotFoundHttpException::class, |
| 197 | + 'Invalid query parameter "suit": expecting an int or string, got bool.', |
| 198 | + ]; |
| 199 | + yield 'parameter found and backing type not valid backing value for enum' => [ |
| 200 | + Request::create('/', 'GET', ['suit' => 10.99]), |
| 201 | + new ArgumentMetadata('suit', Suit::class, false, false, false, attributes: [new MapQueryParameter()]), |
| 202 | + [], |
| 203 | + NotFoundHttpException::class, |
| 204 | + 'Invalid query parameter "suit":', |
| 205 | + ]; |
| 206 | + |
179 | 207 | yield 'parameter not found but nullable' => [
|
180 | 208 | Request::create('/', 'GET'),
|
181 | 209 | new ArgumentMetadata('firstName', 'string', false, false, false, true, [new MapQueryParameter()]),
|
@@ -203,14 +231,14 @@ public static function provideTestResolve(): iterable
|
203 | 231 | new ArgumentMetadata('standardClass', \stdClass::class, false, false, false, attributes: [new MapQueryParameter()]),
|
204 | 232 | [],
|
205 | 233 | \LogicException::class,
|
206 |
| - '#[MapQueryParameter] cannot be used on controller argument "$standardClass" of type "stdClass"; one of array, string, int, float or bool should be used.', |
| 234 | + '#[MapQueryParameter] cannot be used on controller argument "$standardClass" of type "stdClass"; one of array, string, int, float, bool or \BackedEnum should be used.', |
207 | 235 | ];
|
208 | 236 | yield 'unsupported type variadic' => [
|
209 | 237 | Request::create('/', 'GET', ['standardClass' => 'test']),
|
210 | 238 | new ArgumentMetadata('standardClass', \stdClass::class, true, false, false, attributes: [new MapQueryParameter()]),
|
211 | 239 | [],
|
212 | 240 | \LogicException::class,
|
213 |
| - '#[MapQueryParameter] cannot be used on controller argument "...$standardClass" of type "stdClass"; one of array, string, int, float or bool should be used.', |
| 241 | + '#[MapQueryParameter] cannot be used on controller argument "...$standardClass" of type "stdClass"; one of array, string, int, float, bool or \BackedEnum should be used.', |
214 | 242 | ];
|
215 | 243 | }
|
216 | 244 |
|
|
0 commit comments