Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] use real amazon libs in tests. #283

Merged
merged 1 commit into from
Dec 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions Tests/Fixtures/AmazonS3.php

This file was deleted.

13 changes: 0 additions & 13 deletions Tests/Fixtures/CannedAcl.php

This file was deleted.

16 changes: 0 additions & 16 deletions Tests/Fixtures/S3Client.php

This file was deleted.

52 changes: 28 additions & 24 deletions Tests/Imagine/Cache/Resolver/AmazonS3ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,9 @@
*/
class AmazonS3ResolverTest extends AbstractTest
{
protected function setUp()
{
parent::setUp();

if (!class_exists('AmazonS3')) {
require_once($this->fixturesDir.'/AmazonS3.php');
}
}

public function testNoDoubleSlashesInObjectUrl()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -43,7 +34,7 @@ public function testNoDoubleSlashesInObjectUrl()

public function testObjUrlOptions()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -62,7 +53,7 @@ public function testObjUrlOptions()

public function testBrowserPathNotExisting()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand Down Expand Up @@ -94,11 +85,11 @@ public function testLogNotCreatedObjects()
$response->setContent('foo');
$response->headers->set('Content-Type', 'image/jpeg');

$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('create_object')
->will($this->returnValue($this->getS3ResponseMock(false)))
->will($this->returnValue($this->getCFResponseMock(false)))
;

$logger = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Log\LoggerInterface');
Expand All @@ -119,11 +110,11 @@ public function testCreatedObjectRedirects()
$response->setContent('foo');
$response->headers->set('Content-Type', 'image/jpeg');

$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('create_object')
->will($this->returnValue($this->getS3ResponseMock(true)))
->will($this->returnValue($this->getCFResponseMock(true)))
;
$s3
->expects($this->once())
Expand All @@ -141,7 +132,7 @@ public function testCreatedObjectRedirects()

public function testResolveNewObject()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -156,7 +147,7 @@ public function testResolveNewObject()

public function testResolveRedirectsOnExisting()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -179,7 +170,7 @@ public function testResolveRedirectsOnExisting()

public function testRemove()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -190,7 +181,7 @@ public function testRemove()
->expects($this->once())
->method('delete_object')
->with('images.example.com', 'thumb/some-folder/targetpath.jpg')
->will($this->returnValue($this->getS3ResponseMock(true)))
->will($this->returnValue($this->getCFResponseMock(true)))
;

$resolver = new AmazonS3Resolver($s3, 'images.example.com');
Expand All @@ -199,7 +190,7 @@ public function testRemove()

public function testRemoveNotExisting()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->once())
->method('if_object_exists')
Expand All @@ -217,7 +208,7 @@ public function testRemoveNotExisting()

public function testClearIsDisabled()
{
$s3 = $this->getMock('AmazonS3');
$s3 = $this->getAmazonS3Mock();
$s3
->expects($this->never())
->method('delete_object')
Expand All @@ -227,9 +218,9 @@ public function testClearIsDisabled()
$resolver->clear('');
}

protected function getS3ResponseMock($ok = true)
protected function getCFResponseMock($ok = true)
{
$s3Response = $this->getMock('AmazonS3Response');
$s3Response = $this->getMock('CFResponse', array('isOK'), array(), '', false);
$s3Response
->expects($this->once())
->method('isOK')
Expand All @@ -238,4 +229,17 @@ protected function getS3ResponseMock($ok = true)

return $s3Response;
}

protected function getAmazonS3Mock()
{
$mockedMethods = array(
'if_object_exists',
'create_object',
'get_object_url',
'delete_object',
'authenticate'
);

return $this->getMock('AmazonS3', $mockedMethods, array(), '', false);
}
}
51 changes: 24 additions & 27 deletions Tests/Imagine/Cache/Resolver/AwsS3ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,9 @@
*/
class AwsS3ResolverTest extends AbstractTest
{
protected function setUp()
{
parent::setUp();

if (!class_exists('Aws\S3\S3Client')) {
require_once($this->fixturesDir.'/S3Client.php');
}

if (!class_exists('Aws\S3\Enum\CannedAcl')) {
require_once($this->fixturesDir.'/CannedAcl.php');
}

if (!class_exists('Guzzle\Service\Resource\Model')) {
require_once($this->fixturesDir.'/Model.php');
}
}

public function testNoDoubleSlashesInObjectUrl()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -51,7 +34,7 @@ public function testNoDoubleSlashesInObjectUrl()

public function testObjUrlOptions()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -70,7 +53,7 @@ public function testObjUrlOptions()

public function testBrowserPathNotExisting()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand Down Expand Up @@ -102,7 +85,7 @@ public function testLogNotCreatedObjects()
$response->setContent('foo');
$response->headers->set('Content-Type', 'image/jpeg');

$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('putObject')
Expand All @@ -129,7 +112,7 @@ public function testCreatedObjectRedirects()

$responseMock = $this->getS3ResponseMock();

$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('putObject')
Expand All @@ -152,7 +135,7 @@ public function testCreatedObjectRedirects()

public function testResolveNewObject()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -167,7 +150,7 @@ public function testResolveNewObject()

public function testResolveRedirectsOnExisting()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -190,7 +173,7 @@ public function testResolveRedirectsOnExisting()

public function testRemove()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -213,7 +196,7 @@ public function testRemove()

public function testRemoveNotExisting()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->once())
->method('doesObjectExist')
Expand All @@ -231,7 +214,7 @@ public function testRemoveNotExisting()

public function testClearIsDisabled()
{
$s3 = $this->getMock('Aws\S3\S3Client');
$s3 = $this->getS3ClientMock();
$s3
->expects($this->never())
->method('deleteObject')
Expand All @@ -247,4 +230,18 @@ protected function getS3ResponseMock($ok = true)

return $s3Response;
}

protected function getS3ClientMock()
{
$mockedMethods = array(
'deleteObject',
'createObject',
'putObject',
'doesObjectExist',
'getObjectUrl',
);

return $this->getMock('Aws\S3\S3Client', $mockedMethods, array(), '', false);
}

}
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
"require-dev": {
"symfony/browser-kit": "~2.3",
"symfony/yaml": "~2.3",
"doctrine/cache": "~1.1"
"doctrine/cache": "~1.1",
"aws/aws-sdk-php": "~2.4",
"amazonwebservices/aws-sdk-for-php": "~1.0"
},

"suggest": {
"twig/twig": ">=1.0,<2.0-dev"
"twig/twig": "If you'd want to use some handy twig filters",
"aws/aws-sdk-php": "Add it if you'd like to use aws v2 resolver",
"amazonwebservices/aws-sdk-for-php": "Add it if you'd like to use aws v1 resolver"
},

"autoload": {
Expand Down