123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Qiniu\Tests;
- use Qiniu\Http\Client;
- use Qiniu\Http\RequestOptions;
- class HttpTest extends \PHPUnit_Framework_TestCase
- {
- public function testGet()
- {
- $response = Client::get('qiniu.com');
- $this->assertEquals(200, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNull($response->error);
- }
- public function testGetQiniu()
- {
- $response = Client::get('upload.qiniu.com');
- $this->assertEquals(405, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->xReqId());
- $this->assertNotNull($response->xLog());
- $this->assertNotNull($response->error);
- }
- public function testGetTimeout()
- {
- $reqOpt = new RequestOptions();
- $reqOpt->timeout = 1;
- $response = Client::get('localhost:9000/timeout.php', array(), $reqOpt);
- $this->assertEquals(-1, $response->statusCode);
- }
- public function testDelete()
- {
- $response = Client::delete('uc.qbox.me/bucketTagging', array());
- $this->assertEquals(401, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->error);
- }
- public function testDeleteQiniu()
- {
- $response = Client::delete('uc.qbox.me/bucketTagging', array());
- $this->assertEquals(401, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->xReqId());
- $this->assertNotNull($response->xLog());
- $this->assertNotNull($response->error);
- }
- public function testDeleteTimeout()
- {
- $reqOpt = new RequestOptions();
- $reqOpt->timeout = 1;
- $response = Client::delete('localhost:9000/timeout.php', array(), $reqOpt);
- $this->assertEquals(-1, $response->statusCode);
- }
- public function testPost()
- {
- $response = Client::post('qiniu.com', null);
- $this->assertEquals(200, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNull($response->error);
- }
- public function testPostQiniu()
- {
- $response = Client::post('upload.qiniu.com', null);
- $this->assertEquals(400, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->xReqId());
- $this->assertNotNull($response->xLog());
- $this->assertNotNull($response->error);
- }
- public function testPostTimeout()
- {
- $reqOpt = new RequestOptions();
- $reqOpt->timeout = 1;
- $response = Client::post('localhost:9000/timeout.php', null, array(), $reqOpt);
- $this->assertEquals(-1, $response->statusCode);
- }
- public function testPut()
- {
- $response = Client::PUT('uc.qbox.me/bucketTagging', null);
- $this->assertEquals(401, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->error);
- }
- public function testPutQiniu()
- {
- $response = Client::put('uc.qbox.me/bucketTagging', null);
- $this->assertEquals(401, $response->statusCode);
- $this->assertNotNull($response->body);
- $this->assertNotNull($response->xReqId());
- $this->assertNotNull($response->xLog());
- $this->assertNotNull($response->error);
- }
- public function testPutTimeout()
- {
- $reqOpt = new RequestOptions();
- $reqOpt->timeout = 1;
- $response = Client::put('localhost:9000/timeout.php', null, array(), $reqOpt);
- $this->assertEquals(-1, $response->statusCode);
- }
- }
|