PageRenderTime 78ms CodeModel.GetById 20ms RepoModel.GetById 2ms app.codeStats 0ms

/vendor/aws/aws-sdk-php/tests/Aws/Tests/S3/ResumableDownloadTest.php

https://github.com/lslucas/105fm
PHP | 75 lines | 45 code | 6 blank | 24 comment | 0 complexity | 5dc2731d71a5ada190b50c537dc465d6 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Aws\Tests\S3;
  17. use Aws\S3\ResumableDownload;
  18. use Guzzle\Http\Message\Response;
  19. use Guzzle\Http\EntityBody;
  20. use Guzzle\Plugin\Mock\MockPlugin;
  21. /**
  22. * @covers Aws\S3\ResumableDownload
  23. */
  24. class ResumableDownloadTest extends \Guzzle\Tests\GuzzleTestCase
  25. {
  26. /**
  27. * @expectedException \PHPUnit_Framework_Error_Warning
  28. */
  29. public function testEnsuresFilesCanBeOpened()
  30. {
  31. $client = $this->getServiceBuilder()->get('s3');
  32. new ResumableDownload($client, 'test', 'key', '/does/not/exist/foo');
  33. }
  34. public function testDownloadsUsingRangeRequests()
  35. {
  36. $client = $this->getServiceBuilder()->get('s3', true);
  37. $mock = new MockPlugin(array(new Response(200, array('Content-Length' => 9)), new Response(200, array('Content-Length' => 5), '_test')));
  38. $client->addSubscriber($mock);
  39. $target = EntityBody::factory('test');
  40. $target->seek(0, SEEK_END);
  41. $resumable = new ResumableDownload($client, 'test', 'key', $target);
  42. $resumable();
  43. $mocked = $mock->getReceivedRequests();
  44. $this->assertCount(2, $mocked);
  45. $this->assertEquals('HEAD', $mocked[0]->getMethod());
  46. $this->assertEquals('GET', $mocked[1]->getMethod());
  47. $this->assertEquals('bytes=4-8', (string) $mocked[1]->getHeader('Range'));
  48. }
  49. /**
  50. * @expectedException \Aws\Common\Exception\UnexpectedValueException
  51. * @expectedExceptionMessage Message integrity check failed. Expected 5032561e973f16047f3109e6a3f7f173 but got 4ba36d23a78c7393b4900ef38019d8ff
  52. */
  53. public function testEnsuresMd5Match()
  54. {
  55. $client = $this->getServiceBuilder()->get('s3');
  56. $mock = new MockPlugin(array(
  57. new Response(200, array(
  58. 'Content-Length' => 15,
  59. 'Content-MD5' => '5032561e973f16047f3109e6a3f7f173'
  60. )),
  61. new Response(200, array('Content-Length' => 1), '1')
  62. ));
  63. $client->addSubscriber($mock);
  64. $target = EntityBody::factory('11111111111111');
  65. $target->seek(0, SEEK_END);
  66. $resumable = new ResumableDownload($client, 'test', 'key', $target);
  67. $resumable();
  68. }
  69. }