|
14 | 14 | use PHPUnit\Framework\Attributes\DataProvider; |
15 | 15 | use PHPUnit\Framework\Attributes\Group; |
16 | 16 | use PHPUnit\Framework\Attributes\IgnoreDeprecations; |
| 17 | +use PHPUnit\Framework\Attributes\RequiresPhp; |
17 | 18 | use PHPUnit\Framework\Attributes\RequiresPhpExtension; |
18 | 19 | use PHPUnit\Framework\Attributes\TestWith; |
19 | 20 | use PHPUnit\Framework\TestCase; |
20 | 21 | use Symfony\Component\HttpFoundation\Exception\BadRequestException; |
21 | 22 | use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; |
22 | 23 | use Symfony\Component\HttpFoundation\Exception\JsonException; |
23 | 24 | use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; |
24 | | -use Symfony\Component\HttpFoundation\InputBag; |
25 | 25 | use Symfony\Component\HttpFoundation\IpUtils; |
26 | | -use Symfony\Component\HttpFoundation\ParameterBag; |
27 | 26 | use Symfony\Component\HttpFoundation\Request; |
28 | 27 | use Symfony\Component\HttpFoundation\Session\Session; |
29 | 28 | use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
@@ -1281,15 +1280,13 @@ public static function getContentCanBeCalledTwiceWithResourcesProvider() |
1281 | 1280 | ]; |
1282 | 1281 | } |
1283 | 1282 |
|
1284 | | - public static function provideOverloadedMethods() |
| 1283 | + public static function provideMethodsRequiringExplicitBodyParsing() |
1285 | 1284 | { |
1286 | 1285 | return [ |
1287 | 1286 | ['PUT'], |
1288 | 1287 | ['DELETE'], |
1289 | 1288 | ['PATCH'], |
1290 | | - ['put'], |
1291 | | - ['delete'], |
1292 | | - ['patch'], |
| 1289 | + ['QUERY'], |
1293 | 1290 | ]; |
1294 | 1291 | } |
1295 | 1292 |
|
@@ -1331,50 +1328,42 @@ public function testGetPayload() |
1331 | 1328 | $this->assertSame([], $req->getPayload()->all()); |
1332 | 1329 | } |
1333 | 1330 |
|
1334 | | - #[DataProvider('provideOverloadedMethods')] |
1335 | | - public function testCreateFromGlobals($method) |
| 1331 | + public function testCreateFromGlobals() |
1336 | 1332 | { |
1337 | | - $normalizedMethod = strtoupper($method); |
1338 | | - |
1339 | 1333 | $_GET['foo1'] = 'bar1'; |
1340 | 1334 | $_POST['foo2'] = 'bar2'; |
1341 | 1335 | $_COOKIE['foo3'] = 'bar3'; |
1342 | 1336 | $_FILES['foo4'] = ['bar4']; |
1343 | 1337 | $_SERVER['foo5'] = 'bar5'; |
1344 | 1338 |
|
1345 | 1339 | $request = Request::createFromGlobals(); |
1346 | | - $this->assertEquals('bar1', $request->query->get('foo1'), '::fromGlobals() uses values from $_GET'); |
1347 | | - $this->assertEquals('bar2', $request->request->get('foo2'), '::fromGlobals() uses values from $_POST'); |
1348 | | - $this->assertEquals('bar3', $request->cookies->get('foo3'), '::fromGlobals() uses values from $_COOKIE'); |
1349 | | - $this->assertEquals(['bar4'], $request->files->get('foo4'), '::fromGlobals() uses values from $_FILES'); |
1350 | | - $this->assertEquals('bar5', $request->server->get('foo5'), '::fromGlobals() uses values from $_SERVER'); |
1351 | | - $this->assertInstanceOf(InputBag::class, $request->request); |
1352 | | - $this->assertInstanceOf(ParameterBag::class, $request->request); |
| 1340 | + $this->assertEquals('bar1', $request->query->get('foo1'), '::createFromGlobals() uses values from $_GET'); |
| 1341 | + $this->assertEquals('bar2', $request->request->get('foo2'), '::createFromGlobals() uses values from $_POST'); |
| 1342 | + $this->assertEquals('bar3', $request->cookies->get('foo3'), '::createFromGlobals() uses values from $_COOKIE'); |
| 1343 | + $this->assertEquals(['bar4'], $request->files->get('foo4'), '::createFromGlobals() uses values from $_FILES'); |
| 1344 | + $this->assertEquals('bar5', $request->server->get('foo5'), '::createFromGlobals() uses values from $_SERVER'); |
| 1345 | + } |
| 1346 | + |
| 1347 | + public function testGetRealMethod() |
| 1348 | + { |
| 1349 | + Request::enableHttpMethodParameterOverride(); |
| 1350 | + $request = new Request(request: ['_method' => 'PUT'], server: ['REQUEST_METHOD' => 'PoSt']); |
1353 | 1351 |
|
1354 | | - unset($_GET['foo1'], $_POST['foo2'], $_COOKIE['foo3'], $_FILES['foo4'], $_SERVER['foo5']); |
| 1352 | + $this->assertEquals('POST', $request->getRealMethod(), '->getRealMethod() returns the uppercased request method, even if it has been overridden'); |
1355 | 1353 |
|
| 1354 | + $this->disableHttpMethodParameterOverride(); |
| 1355 | + } |
| 1356 | + |
| 1357 | + #[RequiresPhp('< 8.4')] |
| 1358 | + #[DataProvider('provideMethodsRequiringExplicitBodyParsing')] |
| 1359 | + public function testFormUrlEncodedBodyParsing(string $method) |
| 1360 | + { |
1356 | 1361 | $_SERVER['REQUEST_METHOD'] = $method; |
1357 | 1362 | $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; |
1358 | | - $request = RequestContentProxy::createFromGlobals(); |
1359 | | - $this->assertEquals($normalizedMethod, $request->getMethod()); |
1360 | | - $this->assertEquals('mycontent', $request->request->get('content')); |
1361 | | - $this->assertInstanceOf(InputBag::class, $request->request); |
1362 | | - $this->assertInstanceOf(ParameterBag::class, $request->request); |
1363 | 1363 |
|
1364 | | - unset($_SERVER['REQUEST_METHOD'], $_SERVER['CONTENT_TYPE']); |
1365 | | - |
1366 | | - Request::createFromGlobals(); |
1367 | | - Request::enableHttpMethodParameterOverride(); |
1368 | | - $_POST['_method'] = $method; |
1369 | | - $_POST['foo6'] = 'bar6'; |
1370 | | - $_SERVER['REQUEST_METHOD'] = 'PoSt'; |
1371 | | - $request = Request::createFromGlobals(); |
1372 | | - $this->assertEquals($normalizedMethod, $request->getMethod()); |
1373 | | - $this->assertEquals('POST', $request->getRealMethod()); |
1374 | | - $this->assertEquals('bar6', $request->request->get('foo6')); |
| 1364 | + $request = RequestContentProxy::createFromGlobals(); |
1375 | 1365 |
|
1376 | | - unset($_POST['_method'], $_POST['foo6'], $_SERVER['REQUEST_METHOD']); |
1377 | | - $this->disableHttpMethodParameterOverride(); |
| 1366 | + $this->assertEquals('mycontent', $request->request->get('content')); |
1378 | 1367 | } |
1379 | 1368 |
|
1380 | 1369 | public function testOverrideGlobals() |
@@ -2675,7 +2664,7 @@ class RequestContentProxy extends Request |
2675 | 2664 | { |
2676 | 2665 | public function getContent($asResource = false) |
2677 | 2666 | { |
2678 | | - return http_build_query(['_method' => 'PUT', 'content' => 'mycontent'], '', '&'); |
| 2667 | + return http_build_query(['content' => 'mycontent'], '', '&'); |
2679 | 2668 | } |
2680 | 2669 | } |
2681 | 2670 |
|
|
0 commit comments