diff options
author | Marcel Hernandez <[email protected]> | 2018-10-02 17:11:01 +0200 |
---|---|---|
committer | Marcel Hernandez <[email protected]> | 2018-10-02 17:11:01 +0200 |
commit | fc99d361aa1c3764f0438b7de16d89d17d1bc12c (patch) | |
tree | de3c722dd0810337c181c72403d5a10e2c149aea | |
parent | 2b08826ff3dd916c214ad8212824f5934e0ca3c2 (diff) |
fix tests:
- ServerRequest::withProtocol() method is broken on Diactoros
- Parsed body and raw body are mutually exclusive
- UploadFile needs an empty stream when upload fails
-rw-r--r-- | src/PSR7Client.php | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 111ab6ce..b12159a5 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -93,7 +93,6 @@ class PSR7Client $request = $request ->withCookieParams($ctx['cookies']) - ->withProtocolVersion($ctx['protocol']) ->withQueryParams($query) ->withUploadedFiles($this->wrapUploads($ctx['uploads'])); @@ -105,17 +104,15 @@ class PSR7Client $request = $request->withHeader($name, $value); } - if ($body !== null) { + if ($ctx['parsed']) { + $request = $request->withParsedBody(json_decode($body, true)); + } else if ($body !== null) { $bodyStream = $this->streamFactory->createStream($body); $bodyStream->write($body); $request = $request->withBody($bodyStream); } - if ($ctx['parsed']) { - $request = $request->withParsedBody(json_decode($body, true)); - } - return $request; } @@ -175,8 +172,12 @@ class PSR7Client continue; } + $stream = UPLOAD_ERR_OK === $f['error'] ? + $this->streamFactory->createStreamFromFile($f['tmpName']) : + $this->streamFactory->createStream(); + $result[$index] = $this->uploadsFactory->createUploadedFile( - $this->streamFactory->createStreamFromFile($f['tmpName']), + $stream, $f['size'], $f['error'], $f['name'], |