public function testFromUploadIdFactoryWorks()
 {
     $uploadId = $this->getMockBuilder('Mss\\S3\\Model\\MultipartUpload\\UploadId')->setMethods(array('toParams'))->getMock();
     $uploadId->expects($this->any())->method('toParams')->will($this->returnValue(array('Bucket' => 'foo', 'Key' => 'bar', 'UploadId' => 'baz')));
     $client = $this->getServiceBuilder()->get('s3');
     $mock = $this->setMockResponse($client, array('s3/list_parts_page_2'));
     $state = TransferState::fromUploadId($client, $uploadId);
     $this->assertInstanceOf('Mss\\S3\\Model\\MultipartUpload\\TransferState', $state);
     $this->assertEquals(1, count($mock->getReceivedRequests()));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  * @throws InvalidArgumentException when attempting to resume a transfer using a non-seekable stream
  * @throws InvalidArgumentException when missing required properties (bucket, key, client, source)
  */
 public function build()
 {
     if ($this->state instanceof TransferState) {
         $this->commandOptions = array_replace($this->commandOptions, $this->state->getUploadId()->toParams());
     }
     if (!isset($this->commandOptions['Bucket']) || !isset($this->commandOptions['Key']) || !$this->client || !$this->source) {
         throw new InvalidArgumentException('You must specify a Bucket, Key, client, and source.');
     }
     if ($this->state && !$this->source->isSeekable()) {
         throw new InvalidArgumentException('You cannot resume a transfer using a non-seekable source.');
     }
     // If no state was set, then create one by initiating or loading a multipart upload
     if (is_string($this->state)) {
         $this->state = TransferState::fromUploadId($this->client, UploadId::fromParams(array('Bucket' => $this->commandOptions['Bucket'], 'Key' => $this->commandOptions['Key'], 'UploadId' => $this->state)));
     } elseif (!$this->state) {
         $this->state = $this->initiateMultipartUpload();
     }
     $options = array_replace(array('min_part_size' => $this->minPartSize, 'part_md5' => (bool) $this->calculatePartMd5, 'concurrency' => $this->concurrency), $this->transferOptions);
     return $this->concurrency > 1 ? new ParallelTransfer($this->client, $this->state, $this->source, $options) : new SerialTransfer($this->client, $this->state, $this->source, $options);
 }