S3Test.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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-2012 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. /**
  26. * @see Zend_Cloud_StorageService_TestCase
  27. */
  28. require_once 'Zend/Cloud/StorageService/TestCase.php';
  29. /**
  30. * @see Zend_Cloud_StorageService_Adapter_S3
  31. */
  32. require_once 'Zend/Cloud/StorageService/Adapter/S3.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Cloud
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Cloud_StorageService_Adapter_S3Test
  41. extends Zend_Cloud_StorageService_TestCase
  42. {
  43. protected $_clientType = 'Zend_Service_Amazon_S3';
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @access public
  48. * @static
  49. */
  50. public static function main()
  51. {
  52. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  53. $result = PHPUnit_TextUI_TestRunner::run($suite);
  54. }
  55. /**
  56. * Sets up this test case
  57. *
  58. * @return void
  59. */
  60. public function setUp()
  61. {
  62. parent::setUp();
  63. // Create the bucket here
  64. $s3 = new Zend_Service_Amazon_S3(
  65. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY),
  66. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY)
  67. );
  68. $s3->createBucket(
  69. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME)
  70. );
  71. }
  72. // TODO: Create a custom test for S3 that checks fetchMetadata() with an object that has custom metadata.
  73. public function testFetchMetadata()
  74. {
  75. $this->markTestIncomplete('S3 doesn\'t support storing metadata after an item is created.');
  76. }
  77. public function testStoreMetadata()
  78. {
  79. $this->markTestSkipped('S3 doesn\'t support storing metadata after an item is created.');
  80. }
  81. public function testDeleteMetadata()
  82. {
  83. $this->markTestSkipped('S3 doesn\'t support storing metadata after an item is created.');
  84. }
  85. /**
  86. * Tears down this test case
  87. *
  88. * @return void
  89. */
  90. public function tearDown()
  91. {
  92. if (!$this->_config) {
  93. return;
  94. }
  95. // Delete the bucket here
  96. $s3 = new Zend_Service_Amazon_S3(
  97. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY),
  98. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY)
  99. );
  100. $s3->removeBucket(
  101. $this->_config->get(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME)
  102. );
  103. parent::tearDown();
  104. }
  105. protected function _getConfig()
  106. {
  107. if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  108. || !constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  109. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID')
  110. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')
  111. || !defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET')
  112. ) {
  113. $this->markTestSkipped("Amazon S3 access not configured, skipping test");
  114. }
  115. $config = new Zend_Config(array(
  116. Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',
  117. Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  118. Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY'),
  119. Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME => constant('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET'),
  120. ));
  121. return $config;
  122. }
  123. }
  124. if (PHPUnit_MAIN_METHOD == 'Zend_Cloud_StorageService_Adapter_S3Test::main') {
  125. Zend_Cloud_StorageService_Adapter_S3Test::main();
  126. }