|
12 | 12 | namespaceSymfony\Component\HttpKernel\Tests\Controller\ArgumentResolver; |
13 | 13 |
|
14 | 14 | usePHPUnit\Framework\TestCase; |
15 | | -useSymfony\Component\HttpFoundation\Exception\BadRequestException; |
16 | 15 | useSymfony\Component\HttpFoundation\Request; |
17 | 16 | useSymfony\Component\HttpKernel\Controller\ArgumentResolver\BackedEnumValueResolver; |
18 | 17 | useSymfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; |
| 18 | +useSymfony\Component\HttpKernel\Exception\NotFoundHttpException; |
19 | 19 | useSymfony\Component\HttpKernel\Tests\Fixtures\Suit; |
20 | 20 |
|
21 | 21 | /** |
@@ -59,14 +59,14 @@ public function provideTestSupportsData(): iterable |
59 | 59 | false, |
60 | 60 | ]; |
61 | 61 |
|
62 | | -yield'supports variadics' => [ |
| 62 | +yield'unsupported variadic' => [ |
63 | 63 | self::createRequest(['suit' => ['H','S']]), |
64 | 64 | self::createArgumentMetadata( |
65 | 65 | 'suit', |
66 | 66 | Suit::class, |
67 | 67 | variadic:true, |
68 | 68 | ), |
69 | | -true, |
| 69 | +false, |
70 | 70 | ]; |
71 | 71 | } |
72 | 72 |
|
@@ -98,54 +98,30 @@ public function provideTestResolveData(): iterable |
98 | 98 | ), |
99 | 99 | [null], |
100 | 100 | ]; |
101 | | - |
102 | | -yield'with variadics' => [ |
103 | | -self::createRequest(['suits' => ['H',null,'S']]), |
104 | | -self::createArgumentMetadata( |
105 | | -'suits', |
106 | | - Suit::class, |
107 | | - variadic:true |
108 | | - ), |
109 | | - [Suit::Hearts,null, Suit::Spades], |
110 | | - ]; |
111 | 101 | } |
112 | 102 |
|
113 | | -publicfunctiontestResolveThrowsOnInvalidValue() |
| 103 | +publicfunctiontestResolveThrowsNotFoundOnInvalidValue() |
114 | 104 | { |
115 | 105 | $resolver =newBackedEnumValueResolver(); |
116 | 106 | $request =self::createRequest(['suit' =>'foo']); |
117 | 107 | $metadata =self::createArgumentMetadata('suit', Suit::class); |
118 | 108 |
|
119 | | -$this->expectException(BadRequestException::class); |
120 | | -$this->expectExceptionMessage('Could not resolve the "suit" controller argument: "foo" is not a valid backing value for enum "Symfony\Component\HttpKernel\Tests\Fixtures\Suit"'); |
| 109 | +$this->expectException(NotFoundHttpException::class); |
| 110 | +$this->expectExceptionMessage('Could not resolve the "Symfony\Component\HttpKernel\Tests\Fixtures\Suit $suit" controller argument: "foo" is not a valid backing value for enum'); |
121 | 111 |
|
122 | 112 | /** @var \Generator $results */ |
123 | 113 | $results =$resolver->resolve($request,$metadata); |
124 | 114 | iterator_to_array($results); |
125 | 115 | } |
126 | 116 |
|
127 | | -publicfunctiontestResolveThrowsOnNonVariadicArgumentWithMultipleValues() |
| 117 | +publicfunctiontestResolveThrowsOnUnexpectedType() |
128 | 118 | { |
129 | 119 | $resolver =newBackedEnumValueResolver(); |
130 | | -$request =self::createRequest(['suit' =>['H','S']]); |
| 120 | +$request =self::createRequest(['suit' =>false]); |
131 | 121 | $metadata =self::createArgumentMetadata('suit', Suit::class); |
132 | 122 |
|
133 | | -$this->expectException(BadRequestException::class); |
134 | | -$this->expectExceptionMessage('Could not resolve the "suit" controller argument: Symfony\Component\HttpKernel\Tests\Fixtures\Suit::from(): Argument #1 ($value) must be of type string, array given'); |
135 | | - |
136 | | -/** @var \Generator $results */ |
137 | | -$results =$resolver->resolve($request,$metadata); |
138 | | -iterator_to_array($results); |
139 | | - } |
140 | | - |
141 | | -publicfunctiontestResolveThrowsOnVariadicArgumentWithNonArrayValue() |
142 | | - { |
143 | | -$resolver =newBackedEnumValueResolver(); |
144 | | -$request =self::createRequest(['suits' =>'H']); |
145 | | -$metadata =self::createArgumentMetadata('suits', Suit::class, variadic:true); |
146 | | - |
147 | | -$this->expectException(BadRequestException::class); |
148 | | -$this->expectExceptionMessage('Unexpected value for parameter "suits": expecting "array", got "string".'); |
| 123 | +$this->expectException(\LogicException::class); |
| 124 | +$this->expectExceptionMessage('Could not resolve the "Symfony\Component\HttpKernel\Tests\Fixtures\Suit $suit" controller argument: expecting an int or string, got bool.'); |
149 | 125 |
|
150 | 126 | /** @var \Generator $results */ |
151 | 127 | $results =$resolver->resolve($request,$metadata); |
|