|
| 1 | +<?php |
| 2 | +namespace PHPQueue\Backend; |
| 3 | + |
| 4 | +class AmazonS3Test extends \PHPUnit_Framework_TestCase |
| 5 | +{ |
| 6 | + /** |
| 7 | + * @var \PHPQueue\Backend\AmazonS3 |
| 8 | + */ |
| 9 | + private $object; |
| 10 | + private $test_upload_bucket = 'phpqueuetestbucket'; |
| 11 | + |
| 12 | + public function setUp() |
| 13 | + { |
| 14 | + parent::setUp(); |
| 15 | + if (!class_exists('\AmazonS3')) |
| 16 | + { |
| 17 | + $this->markTestSkipped('Amazon PHP SDK not installed'); |
| 18 | + } |
| 19 | + else |
| 20 | + { |
| 21 | + $options = array( |
| 22 | + 'region' => \AmazonS3::REGION_APAC_SE1 |
| 23 | + , 'region_website' => \AmazonS3::REGION_APAC_SE1_WEBSITE |
| 24 | + , 'bucket' => $this->test_upload_bucket |
| 25 | + // , 'sqs_options' => array( |
| 26 | + // 'key' => 'xxx' |
| 27 | + // , 'secret' => 'xxx' |
| 28 | + // ) |
| 29 | + ); |
| 30 | + $this->object = new AmazonS3($options); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + public function testManageContainers() |
| 35 | + { |
| 36 | + $container_name = 'test'.time(); |
| 37 | + |
| 38 | + $result = $this->object->listContainers(); |
| 39 | + $this->assertEmpty($result); |
| 40 | + |
| 41 | + $result = $this->object->createContainer($container_name); |
| 42 | + $this->assertTrue($result); |
| 43 | + |
| 44 | + $result = $this->object->listContainers(); |
| 45 | + $this->assertEquals(1, count($result)); |
| 46 | + |
| 47 | + $result = $this->object->deleteContainer($container_name); |
| 48 | + $this->assertTrue($result); |
| 49 | + |
| 50 | + $result = $this->object->listContainers(); |
| 51 | + $this->assertEmpty($result); |
| 52 | + } |
| 53 | + |
| 54 | + public function testAdd() |
| 55 | + { |
| 56 | + sleep(1); |
| 57 | + $result = $this->object->createContainer($this->test_upload_bucket); |
| 58 | + $this->assertTrue($result); |
| 59 | + |
| 60 | + $this->object->setContainer($this->test_upload_bucket); |
| 61 | + $file = __DIR__ . '/cc_logo.jpg'; |
| 62 | + $result = $this->object->putFile('image.jpg', $file); |
| 63 | + $this->assertTrue($result); |
| 64 | + |
| 65 | + $result = $this->object->listFiles(); |
| 66 | + $this->assertNotEmpty($result); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @depends testAdd |
| 71 | + */ |
| 72 | + public function testGet() |
| 73 | + { |
| 74 | + $result = $this->object->fetchFile('image.jpg', __DIR__ . '/downloads'); |
| 75 | + $this->assertNotEmpty($result); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @depends testAdd |
| 80 | + * @expectedException \PHPQueue\Exception\BackendException |
| 81 | + */ |
| 82 | + public function testClearInvalidName() |
| 83 | + { |
| 84 | + $fake_filename = 'xxx'; |
| 85 | + $this->object->clear($fake_filename); |
| 86 | + $this->fail("Should not be able to delete."); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @depends testAdd |
| 91 | + */ |
| 92 | + public function testClear() |
| 93 | + { |
| 94 | + $result = $this->object->clear('image.jpg'); |
| 95 | + $this->assertTrue($result); |
| 96 | + |
| 97 | + $result = $this->object->deleteContainer($this->test_upload_bucket); |
| 98 | + $this->assertTrue($result); |
| 99 | + } |
| 100 | +} |
0 commit comments