1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;
#[RequiresPhp('>=8.4')]
class RequestFunctionalTest extends TestCase
{
/** @var resource|false */
private static $server;
public static function setUpBeforeClass(): void
{
$spec = [
1 => ['file', '/dev/null', 'w'],
2 => ['file', '/dev/null', 'w'],
];
if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/request-functional')) {
self::markTestSkipped('PHP server unable to start.');
}
sleep(1);
}
public static function tearDownAfterClass(): void
{
if (self::$server) {
proc_terminate(self::$server);
proc_close(self::$server);
}
}
public static function provideMethodsRequiringExplicitBodyParsing()
{
return [
['PUT'],
['DELETE'],
['PATCH'],
// PHP’s built-in server doesn’t support QUERY
];
}
#[DataProvider('provideMethodsRequiringExplicitBodyParsing')]
public function testFormUrlEncodedBodyParsing(string $method)
{
$this->markTestSkipped('Test currently failing on Debian.');
$response = file_get_contents('http://localhost:8054/', false, stream_context_create([
'http' => [
'header' => 'Content-type: application/x-www-form-urlencoded',
'method' => $method,
'content' => http_build_query(['foo' => 'bar']),
],
]));
$this->assertSame(['foo' => 'bar'], json_decode($response, true)['request']);
}
#[DataProvider('provideMethodsRequiringExplicitBodyParsing')]
public function testMultipartFormDataBodyParsing(string $method)
{
$this->markTestSkipped('Test currently failing on Debian.');
$response = file_get_contents('http://localhost:8054/', false, stream_context_create([
'http' => [
'header' => 'Content-Type: multipart/form-data; boundary=boundary',
'method' => $method,
'content' => "--boundary\r\n".
"Content-Disposition: form-data; name=foo\r\n".
"\r\n".
"bar\r\n".
"--boundary\r\n".
"Content-Disposition: form-data; name=baz; filename=baz.txt\r\n".
"Content-Type: text/plain\r\n".
"\r\n".
"qux\r\n".
'--boundary--',
],
]));
$data = json_decode($response, true);
$this->assertSame(['foo' => 'bar'], $data['request']);
$this->assertSame(['baz' => [
'clientOriginalName' => 'baz.txt',
'clientMimeType' => 'text/plain',
'content' => 'qux',
]], $data['files']);
}
}
|