123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace Qiniu\Tests {
- use PHPUnit\Framework\TestCase;
- use Qiniu\Config;
- class ConfigTest extends TestCase
- {
- protected $accessKey;
- protected $bucketName;
- /**
- * @before
- */
- protected function setUpAkAndBucket()
- {
- global $accessKey;
- $this->accessKey = $accessKey;
- global $bucketName;
- $this->bucketName = $bucketName;
- }
- public function testGetApiHost()
- {
- $conf = new Config();
- $hasException = false;
- $apiHost = '';
- try {
- $apiHost = $conf->getApiHost($this->accessKey, $this->bucketName);
- } catch (\Exception $e) {
- $hasException = true;
- }
- $this->assertFalse($hasException);
- }
- public function testGetApiHostErrored()
- {
- $conf = new Config();
- $hasException = false;
- try {
- $conf->getApiHost($this->accessKey, "fakebucket");
- } catch (\Exception $e) {
- $hasException = true;
- }
- $this->assertTrue($hasException);
- }
- public function testGetApiHostV2()
- {
- $conf = new Config();
- list($apiHost, $err) = $conf->getApiHostV2($this->accessKey, $this->bucketName);
- $this->assertNull($err);
- }
- public function testGetApiHostV2Errored()
- {
- $conf = new Config();
- list($apiHost, $err) = $conf->getApiHostV2($this->accessKey, "fakebucket");
- $this->assertNotNull($err->code());
- $this->assertEquals(631, $err->code());
- $this->assertNull($apiHost);
- }
- public function testSetUcHost()
- {
- $conf = new Config();
- $this->assertEquals("http://uc.qbox.me", $conf->getUcHost());
- $conf->setUcHost("uc.example.com");
- $this->assertEquals("http://uc.example.com", $conf->getUcHost());
- $conf = new Config();
- $conf->useHTTPS = true;
- $this->assertEquals("https://uc.qbox.me", $conf->getUcHost());
- $conf->setUcHost("uc.example.com");
- $this->assertEquals("https://uc.example.com", $conf->getUcHost());
- }
- public function testGetRegionWithCustomDomain()
- {
- $conf = new Config();
- $conf->setQueryRegionHost(
- "uc.qbox.me"
- );
- list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
- $this->assertNull($err);
- }
- public function testGetRegionWithBackupDomains()
- {
- $conf = new Config();
- $conf->setQueryRegionHost(
- "fake-uc.phpsdk.qiniu.com",
- array(
- "unavailable-uc.phpsdk.qiniu.com",
- "uc.qbox.me" // real uc
- )
- );
- list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
- $this->assertNull($err);
- }
- public function testGetRegionWithUcAndBackupDomains()
- {
- $conf = new Config();
- $conf->setUcHost("fake-uc.phpsdk.qiniu.com");
- $conf->setBackupQueryRegionHosts(
- array(
- "unavailable-uc.phpsdk.qiniu.com",
- "uc.qbox.me" // real uc
- )
- );
- list(, $err) = $conf->getRsHostV2($this->accessKey, $this->bucketName);
- $this->assertNull($err);
- }
- }
- }
|