From 4ecd3562b2ef10db9776fb1cb89b6a37ef8a8e39 Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 26 Oct 2016 11:43:12 -0700 Subject: [PATCH] BatchResponse accept a response. --- changelog.txt | 1 + src/Common/Internal/Http/BatchResponse.php | 6 +- src/MediaServices/MediaServicesRestProxy.php | 4 +- .../Internal/Http/BatchResponseTest.php | 62 ++++++++++--------- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/changelog.txt b/changelog.txt index 44da80983..0ca114714 100644 --- a/changelog.txt +++ b/changelog.txt @@ -10,6 +10,7 @@ `getResponses()`. - the `sendContext()` function from `\WindowsAzure\Common\Internal\RestProxy` is replaced by `sendHttpContext()`. - the `send()` function from `\WindowsAzure\MediaServices\MediaServicesRestProxy` is replaced by `sendHttp()`. + - `\WindowsAzure\Common\Internal\Http\BatchResponse` constructor the first parameter is `Response`. - Switch to PHP 5.6. Windows Azure SDK For PHP 0.4.5, 2016-09-26 diff --git a/src/Common/Internal/Http/BatchResponse.php b/src/Common/Internal/Http/BatchResponse.php index 52d39d050..a56034993 100644 --- a/src/Common/Internal/Http/BatchResponse.php +++ b/src/Common/Internal/Http/BatchResponse.php @@ -55,11 +55,13 @@ class BatchResponse /** * Constructor. * - * @param string $content Http response as string + * @param Response $response HTTP response * @param BatchRequest $request Source batch request object */ - public function __construct($content, BatchRequest $request = null) + public function __construct(Response $response , BatchRequest $request = null) { + $content = (string)$response->getBody(); + $params['include_bodies'] = true; $params['input'] = $content; $mimeDecoder = new \Mail_mimeDecode($content); diff --git a/src/MediaServices/MediaServicesRestProxy.php b/src/MediaServices/MediaServicesRestProxy.php index d4a125e60..f736672ce 100644 --- a/src/MediaServices/MediaServicesRestProxy.php +++ b/src/MediaServices/MediaServicesRestProxy.php @@ -1338,7 +1338,7 @@ public function createJob(Job $job, array $inputAssets, array $tasks = null) $body ); - $responses = (new BatchResponse($response->getBody(), $batch))->getResponses(); + $responses = (new BatchResponse($response, $batch))->getResponses(); $jobResponse = $responses[0]; $entry = new Entry(); @@ -1633,7 +1633,7 @@ public function createJobTemplate(JobTemplate $jobTemplate, array $taskTemplates $body ); - $responses = (new BatchResponse($response->getBody(), $batch))->getResponses(); + $responses = (new BatchResponse($response, $batch))->getResponses(); $jobTemplateResponse = $responses[0]; $entry = new Entry(); diff --git a/tests/unit/WindowsAzure/Common/Internal/Http/BatchResponseTest.php b/tests/unit/WindowsAzure/Common/Internal/Http/BatchResponseTest.php index ca35091d2..3a88c36ba 100644 --- a/tests/unit/WindowsAzure/Common/Internal/Http/BatchResponseTest.php +++ b/tests/unit/WindowsAzure/Common/Internal/Http/BatchResponseTest.php @@ -24,6 +24,7 @@ namespace Tests\unit\WindowsAzure\Common\Internal\Http; +use GuzzleHttp\Psr7\Response; use WindowsAzure\Common\Internal\Http\BatchResponse; use WindowsAzure\Common\Internal\Http\BatchRequest; use WindowsAzure\Common\Internal\Http\HttpCallContext; @@ -52,22 +53,23 @@ public function test__construct() // Setup $body = 'test response body'; $encodedBody = - "--batch_956c339e-1ef0-4443-9276-68c12888a3f7\r\n". - "Content-Type: multipart/mixed; boundary=changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". - "\r\n". - "--changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". - "Content-Transfer-Encoding: binary\r\n". - "Content-Type: application/http\r\n". - "\r\n". - "HTTP/1.1 200 OK\r\n". - "content-id: 1\r\n". - "\r\n". - $body. - "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n". - '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; + "--batch_956c339e-1ef0-4443-9276-68c12888a3f7\r\n". + "Content-Type: multipart/mixed; boundary=changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". + "\r\n". + "--changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". + "Content-Transfer-Encoding: binary\r\n". + "Content-Type: application/http\r\n". + "\r\n". + "HTTP/1.1 200 OK\r\n". + "content-id: 1\r\n". + "\r\n". + $body. + "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n". + '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; + $response = new Response(200, [], $encodedBody); // Test - $batchResp = new BatchResponse($encodedBody); + $batchResp = new BatchResponse($response); $result = $batchResp->getResponses(); // Assert @@ -92,22 +94,23 @@ public function test__constructWithRequestSuccess() $batchReq->appendContext($httpCallContext); $encodedBody = - "--batch_956c339e-1ef0-4443-9276-68c12888a3f7\r\n". - "Content-Type: multipart/mixed; boundary=changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". - "\r\n". - "--changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". - "Content-Transfer-Encoding: binary\r\n". - "Content-Type: application/http\r\n". - "\r\n". - "HTTP/1.1 {$statusCode} OK\r\n". - "content-id: 1\r\n". - "\r\n". - $body. - "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n". - '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; + "--batch_956c339e-1ef0-4443-9276-68c12888a3f7\r\n". + "Content-Type: multipart/mixed; boundary=changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". + "\r\n". + "--changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n". + "Content-Transfer-Encoding: binary\r\n". + "Content-Type: application/http\r\n". + "\r\n". + "HTTP/1.1 {$statusCode} OK\r\n". + "content-id: 1\r\n". + "\r\n". + $body. + "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n". + '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; + $response = new Response(200, [], $encodedBody); // Test - $batchResp = new BatchResponse($encodedBody, $batchReq); + $batchResp = new BatchResponse($response, $batchReq); $result = $batchResp->getResponses(); // Assert @@ -146,11 +149,12 @@ public function test__constructWithRequestException() $body. "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n". '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; + $response = new Response(200, [], $encodedBody); $this->setExpectedException('WindowsAzure\Common\ServiceException'); // Test - $batchResp = new BatchResponse($encodedBody, $batchReq); + $batchResp = new BatchResponse($response, $batchReq); $result = $batchResp->getResponses(); } }