S3Test.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cloud_StorageService
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. // Call Zend_Cloud_StorageService_Adapter_S3Test::main() if this source file is executed directly.
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Cloud_StorageService_Adapter_S3Test::main");
  24. }
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. /**
  27. * @see Zend_Cloud_StorageService_TestCase
  28. */
  29. require_once 'Zend/Cloud/StorageService/TestCase.php';
  30. /**
  31. * @see Zend_Cloud_StorageService_Adapter_S3
  32. */
  33. require_once 'Zend/Cloud/StorageService/Adapter/S3.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Cloud
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Cloud_StorageService_Adapter_S3Test
  42. extends Zend_Cloud_StorageService_TestCase
  43. {
  44. protected $_clientType = 'Zend_Service_Amazon_S3';
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @access public
  49. * @static
  50. */
  51. public static function main()
  52. {
  53. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. /**
  57. * Sets up this test case
  58. *
  59. * @return void
  60. */
  61. public function setUp()
  62. {
  63. parent::setUp();
  64. // Create the bucket here
  65. $s3 = new Zend_Service_Amazon_S3(
  66. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY),
  67. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY)
  68. );
  69. $s3->createBucket(
  70. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME)
  71. );
  72. }
  73. // TODO: Create a custom test for S3 that checks fetchMetadata() with an object that has custom metadata.
  74. public function testFetchMetadata()
  75. {
  76. $this->markTestIncomplete('S3 doesn\'t support storing metadata after an item is created.');
  77. }
  78. public function testStoreMetadata()
  79. {
  80. $this->markTestSkipped('S3 doesn\'t support storing metadata after an item is created.');
  81. }
  82. public function testDeleteMetadata()
  83. {
  84. $this->markTestSkipped('S3 doesn\'t support storing metadata after an item is created.');
  85. }
  86. /**
  87. * Tears down this test case
  88. *
  89. * @return void
  90. */
  91. public function tearDown()
  92. {
  93. if (!$this->_config) {
  94. return;
  95. }
  96. // Delete the bucket here
  97. $s3 = new Zend_Service_Amazon_S3(
  98. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY),
  99. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY)
  100. );
  101. $s3->removeBucket(
  102. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME)
  103. );
  104. parent::tearDown();
  105. }
  106. protected function _getConfig()
  107. {
  108. if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  109. || !constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  110. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID')
  111. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')
  112. || !defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET')
  113. ) {
  114. $this->markTestSkipped("Amazon S3 access not configured, skipping test");
  115. }
  116. $config = new Zend_Config(array(
  117. Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',
  118. Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  119. Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY'),
  120. Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME => constant('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET'),
  121. ));
  122. return $config;
  123. }
  124. }
  125. if (PHPUnit_MAIN_METHOD == 'Zend_Cloud_StorageService_Adapter_S3Test::main') {
  126. Zend_Cloud_StorageService_Adapter_S3Test::main();
  127. }