AbstractTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Service/Amazon/Abstract.php';
  4. /**
  5. * Zend_Service_Amazon_Sqs_Queue test case.
  6. */
  7. class AmamzonAbstract extends PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * Prepares the environment before running a test.
  11. */
  12. protected function setUp()
  13. {
  14. parent::setUp();
  15. }
  16. /**
  17. * Cleans up the environment after running a test.
  18. */
  19. protected function tearDown()
  20. {
  21. parent::tearDown();
  22. }
  23. public function testNoKeysThrowException()
  24. {
  25. try {
  26. $class = new TestAmamzonAbstract();
  27. $this->fail('Exception should be thrown when no keys are passed in.');
  28. } catch(Zend_Service_Amazon_Exception $zsae) {}
  29. }
  30. public function testConstructorWithKeysDoesNotThrowException()
  31. {
  32. try {
  33. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  34. } catch(Zend_Service_Amazon_Exception $zsae) {
  35. $this->fail('Exception should be thrown when no keys are passed in.');
  36. }
  37. }
  38. public function testSetStaticKeys()
  39. {
  40. TestAmamzonAbstract::setKeys('TestAccessKey', 'TestSecretKey');
  41. $class = new TestAmamzonAbstract();
  42. $this->assertEquals('TestAccessKey', $class->returnAccessKey());
  43. $this->assertEquals('TestSecretKey', $class->returnSecretKey());
  44. }
  45. public function testPassKeysIntoConstructor()
  46. {
  47. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  48. $this->assertEquals('TestAccessKey', $class->returnAccessKey());
  49. $this->assertEquals('TestSecretKey', $class->returnSecretKey());
  50. }
  51. public function testPassedInKeysOverrideStaticSetKeys()
  52. {
  53. TestAmamzonAbstract::setKeys('TestStaticAccessKey', 'TestStaticSecretKey');
  54. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  55. $this->assertEquals('TestAccessKey', $class->returnAccessKey());
  56. $this->assertEquals('TestSecretKey', $class->returnSecretKey());
  57. }
  58. public function testSetRegion()
  59. {
  60. TestAmamzonAbstract::setRegion('eu-west-1');
  61. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  62. $this->assertEquals('eu-west-1', $class->returnRegion());
  63. }
  64. public function testSetInvalidRegionThrowsException()
  65. {
  66. try {
  67. TestAmamzonAbstract::setRegion('eu-west-1a');
  68. $this->fail('Invalid Region Set with no Exception Thrown');
  69. } catch (Zend_Service_Amazon_Exception $zsae) {
  70. // do nothing
  71. }
  72. }
  73. }
  74. class TestAmamzonAbstract extends Zend_Service_Amazon_Abstract
  75. {
  76. public function returnAccessKey()
  77. {
  78. return $this->_accessKey;
  79. }
  80. public function returnSecretKey()
  81. {
  82. return $this->_secretKey;
  83. }
  84. public function returnRegion()
  85. {
  86. return $this->_region;
  87. }
  88. }