/** * 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(); }
/** * 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); } }
/** * 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; }
/** * 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); }
/** * 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'); }