зеркало из
1
0
Форкнуть 0

BatchResponse accept a response.

This commit is contained in:
Sergey Shandar 2016-10-26 11:43:12 -07:00
Родитель b858108d57
Коммит 4ecd3562b2
4 изменённых файлов: 40 добавлений и 33 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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);

Просмотреть файл

@ -1338,7 +1338,7 @@ class MediaServicesRestProxy extends ServiceRestProxy implements IMediaServices
$body
);
$responses = (new BatchResponse($response->getBody(), $batch))->getResponses();
$responses = (new BatchResponse($response, $batch))->getResponses();
$jobResponse = $responses[0];
$entry = new Entry();
@ -1633,7 +1633,7 @@ class MediaServicesRestProxy extends ServiceRestProxy implements IMediaServices
$body
);
$responses = (new BatchResponse($response->getBody(), $batch))->getResponses();
$responses = (new BatchResponse($response, $batch))->getResponses();
$jobTemplateResponse = $responses[0];
$entry = new Entry();

Просмотреть файл

@ -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 @@ class BatchResponseTest extends \PHPUnit_Framework_TestCase
// 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 @@ class BatchResponseTest extends \PHPUnit_Framework_TestCase
$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 @@ class BatchResponseTest extends \PHPUnit_Framework_TestCase
$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();
}
}