示例#1
0
 /**
  * Tears down this test case
  *
  * @return void
  */
 public function tearDown()
 {
     if (!$this->_config) {
         return;
     }
     // Delete the bucket here
     $s3 = new AmazonS3($this->_config->get(\Zend\Cloud\StorageService\Adapter\S3::AWS_ACCESS_KEY), $this->_config->get(\Zend\Cloud\StorageService\Adapter\S3::AWS_SECRET_KEY));
     $s3->removeBucket($this->_config->get(\Zend\Cloud\StorageService\Adapter\S3::BUCKET_NAME));
     parent::tearDown();
 }
示例#2
0
文件: S3.php 项目: rafalwrzeszcz/zf2
 /**
  * Get a key/value array of metadata for the given path.
  *
  * @param  string $path
  * @param  array $options
  * @return array
  */
 public function fetchMetadata($path, $options = array())
 {
     try {
         return $this->_s3->getInfo($this->_getFullPath($path, $options));
     } catch (Zend\Service\Amazon\S3\Exception $e) {
         throw new Exception\RuntimeException('Error on fetch: ' . $e->getMessage(), $e->getCode(), $e);
     }
 }
示例#3
0
 /**
  * Retrieve client for this stream type
  *
  * @param  string $path
  * @return Zend_Service_Amazon_S3
  */
 protected function _getS3Client($path)
 {
     if ($this->_s3 === null) {
         $url = explode(':', $path);
         if (!$url) {
             throw new Exception\InvalidArgumentException("Unable to parse URL {$path}");
         }
         $this->_s3 = S3::getWrapperClient($url[0]);
         if (!$this->_s3) {
             throw new Exception\RuntimeException("Unknown client for wrapper {$url[0]}");
         }
     }
     return $this->_s3;
 }
示例#4
0
    /**
     * Test get buckets
     *
     * @return void
     */
    public function testGetBuckets()
    {
        $expected  = array('quotes', 'samples');

        // Http Response results
        $this->httpResponse->expects($this->any())
                           ->method('getStatusCode')
                           ->will($this->returnValue(200));
        $rawBody = <<<BODY
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01">
    <Owner>
        <ID>bcaf1ffd86f461ca5fb16fd081034f</ID>
        <DisplayName>webfile</DisplayName>
    </Owner>
    <Buckets>
        <Bucket>
            <Name>quotes</Name>
            <CreationDate>2006-02-03T16:45:09.000Z</CreationDate>
        </Bucket>
        <Bucket>
            <Name>samples</Name>
            <CreationDate>2006-02-03T16:41:58.000Z</CreationDate>
        </Bucket>
    </Buckets>
</ListAllMyBucketsResult>
BODY;
        $this->httpResponse->expects($this->any())
                           ->method('getBody')
                           ->will($this->returnValue($rawBody));

        // Expects to be called only once the method send() then return a Http Response.
        $this->httpClient->expects($this->once())
                         ->method('send')
                         ->will($this->returnValue($this->httpResponse));

        $buckets = $this->amazon->getBuckets();

        $this->assertEquals($expected, $buckets);
    }
示例#5
0
文件: S3RestTest.php 项目: rudrud/zf2
 /**
  * Test invalid bucket name (label starting with dash)
  *
  * @return void
  */
 public function testBucketNameLabelDash()
 {
     $this->setExpectedException('\\Zend\\Service\\Amazon\\S3\\Exception\\InvalidArgumentException');
     $this->amazon->_validBucketName('iam.aninvalid.-bucketname');
 }