ConfigTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Qiniu\Tests {
  3. use Qiniu\Config;
  4. class ConfigTest extends \PHPUnit_Framework_TestCase
  5. {
  6. protected $accessKey;
  7. protected $bucketName;
  8. protected function setUp()
  9. {
  10. global $accessKey;
  11. $this->accessKey = $accessKey;
  12. global $bucketName;
  13. $this->bucketName = $bucketName;
  14. }
  15. public function testGetApiHost()
  16. {
  17. $conf = new Config();
  18. $hasException = false;
  19. $apiHost = '';
  20. try {
  21. $apiHost = $conf->getApiHost($this->accessKey, $this->bucketName);
  22. } catch (\Exception $e) {
  23. $hasException = true;
  24. }
  25. $this->assertFalse($hasException);
  26. $this->assertEquals('http://api.qiniu.com', $apiHost);
  27. }
  28. public function testGetApiHostErrored()
  29. {
  30. $conf = new Config();
  31. $hasException = false;
  32. try {
  33. $conf->getApiHost($this->accessKey, "fakebucket");
  34. } catch (\Exception $e) {
  35. $hasException = true;
  36. }
  37. $this->assertTrue($hasException);
  38. }
  39. public function testGetApiHostV2()
  40. {
  41. $conf = new Config();
  42. list($apiHost, $err) = $conf->getApiHostV2($this->accessKey, $this->bucketName);
  43. $this->assertNull($err);
  44. $this->assertEquals('http://api.qiniu.com', $apiHost);
  45. }
  46. public function testGetApiHostV2Errored()
  47. {
  48. $conf = new Config();
  49. list($apiHost, $err) = $conf->getApiHostV2($this->accessKey, "fakebucket");
  50. $this->assertNotNull($err->code());
  51. $this->assertEquals(631, $err->code());
  52. $this->assertNull($apiHost);
  53. }
  54. }
  55. }