/** * @covers \DoctrineORMModule\Yuml\YumlController::indexAction */ public function testIndexActionWillFailOnMalformedResponse() { $response = $this->getMock('Zend\\Http\\Response'); $this->httpClient->expects($this->any())->method('send')->will($this->returnValue($response)); $response->expects($this->any())->method('isSuccess')->will($this->returnValue(false)); $this->setExpectedException('UnexpectedValueException'); $this->controller->indexAction(); }
/** * Test create bucket * * @return void */ public function testCreateBuckets() { //Valid bucket name $bucket = 'iamavalidbucket'; $location = ''; $accessKey = 'AKIAIDCZ2WXN6NNB7YZA'; $secretKey = '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'; $requestDate = DateTime::createFromFormat(DateTime::RFC1123, 'Tue, 15 May 2012 15:18:31 +0000'); $this->amazon->setRequestDate($requestDate); $this->amazon->setKeys($accessKey, $secretKey); //Fake keys /** * Check of request inside _makeRequest * */ $this->uriHttp->expects($this->once())->method('getHost')->with()->will($this->returnValue('s3.amazonaws.com')); $this->uriHttp->expects($this->once())->method('setHost')->with('iamavalidbucket.s3.amazonaws.com'); $this->uriHttp->expects($this->once())->method('setPath')->with('/'); $this->httpClient->expects($this->once())->method('setUri')->with($this->uriHttp); $this->httpClient->expects($this->once())->method('setMethod')->with('PUT'); $this->httpClient->expects($this->once())->method('setHeaders')->with(array("Date" => "Tue, 15 May 2012 15:18:31 +0000", "Content-Type" => "application/xml", "Authorization" => "AWS " . $accessKey . ":Y+T4nZxI1wBi1Yn1BMnOK9CDiOM=")); /** * Fake response inside _makeRequest * */ // Http Response results $this->httpResponse->expects($this->any())->method('getStatusCode')->will($this->returnValue(200)); // 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)); $response = $this->amazon->createBucket($bucket, $location); $this->assertTrue($response); }
/** * 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); }