mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Merge pull request #202 from PowerKiKi/support-non-parsed-psr7
Support non pre-parsed PSR-7 request body
This commit is contained in:
commit
9d37f4c0d9
@ -499,6 +499,10 @@ class Helper
|
||||
Utils::printSafeJson($bodyParams)
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($bodyParams)) {
|
||||
$bodyParams = json_decode($request->getBody(), true);
|
||||
}
|
||||
} else {
|
||||
$bodyParams = $request->getParsedBody();
|
||||
|
||||
|
@ -47,15 +47,17 @@ class StandardServerTest extends TestCase
|
||||
'query' => '{f1}'
|
||||
]);
|
||||
|
||||
$request = $this->preparePsrRequest('application/json', $body);
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'f1' => 'f1'
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertPsrRequestEquals($expected, $request);
|
||||
$preParsedRequest = $this->preparePsrRequest('application/json', $body, true);
|
||||
$this->assertPsrRequestEquals($expected, $preParsedRequest);
|
||||
|
||||
$notPreParsedRequest = $this->preparePsrRequest('application/json', $body, false);
|
||||
$this->assertPsrRequestEquals($expected, $notPreParsedRequest);
|
||||
}
|
||||
|
||||
private function executePsrRequest($psrRequest)
|
||||
@ -73,21 +75,20 @@ class StandardServerTest extends TestCase
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function preparePsrRequest($contentType, $content, $method = 'POST')
|
||||
private function preparePsrRequest($contentType, $content, $preParseBody)
|
||||
{
|
||||
$psrRequestBody = new PsrStreamStub();
|
||||
$psrRequestBody->content = $content;
|
||||
|
||||
$psrRequest = new PsrRequestStub();
|
||||
$psrRequest->headers['content-type'] = [$contentType];
|
||||
$psrRequest->method = $method;
|
||||
$psrRequest->method = 'POST';
|
||||
$psrRequest->body = $psrRequestBody;
|
||||
|
||||
if ($contentType === 'application/json') {
|
||||
if ($preParseBody && $contentType === 'application/json') {
|
||||
$parsedBody = json_decode($content, true);
|
||||
$parsedBody = $parsedBody === false ? null : $parsedBody;
|
||||
} else {
|
||||
$parsedBody = null;
|
||||
$parsedBody = [];
|
||||
}
|
||||
|
||||
$psrRequest->parsedBody = $parsedBody;
|
||||
|
Loading…
x
Reference in New Issue
Block a user