Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
BatchResponse accept a response.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shandar committed Oct 26, 2016
1 parent b858108 commit 4ecd356
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Common/Internal/Http/BatchResponse.php
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/MediaServices/MediaServicesRestProxy.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
62 changes: 33 additions & 29 deletions tests/unit/WindowsAzure/Common/Internal/Http/BatchResponseTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 4ecd356

Please sign in to comment.