HttpTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Qiniu\Tests;
  3. use Qiniu\Http\Client;
  4. use Qiniu\Http\RequestOptions;
  5. class HttpTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testGet()
  8. {
  9. $response = Client::get('qiniu.com');
  10. $this->assertEquals(200, $response->statusCode);
  11. $this->assertNotNull($response->body);
  12. $this->assertNull($response->error);
  13. }
  14. public function testGetQiniu()
  15. {
  16. $response = Client::get('upload.qiniu.com');
  17. $this->assertEquals(405, $response->statusCode);
  18. $this->assertNotNull($response->body);
  19. $this->assertNotNull($response->xReqId());
  20. $this->assertNotNull($response->xLog());
  21. $this->assertNotNull($response->error);
  22. }
  23. public function testGetTimeout()
  24. {
  25. $reqOpt = new RequestOptions();
  26. $reqOpt->timeout = 1;
  27. $response = Client::get('localhost:9000/timeout.php', array(), $reqOpt);
  28. $this->assertEquals(-1, $response->statusCode);
  29. }
  30. public function testDelete()
  31. {
  32. $response = Client::delete('uc.qbox.me/bucketTagging', array());
  33. $this->assertEquals(401, $response->statusCode);
  34. $this->assertNotNull($response->body);
  35. $this->assertNotNull($response->error);
  36. }
  37. public function testDeleteQiniu()
  38. {
  39. $response = Client::delete('uc.qbox.me/bucketTagging', array());
  40. $this->assertEquals(401, $response->statusCode);
  41. $this->assertNotNull($response->body);
  42. $this->assertNotNull($response->xReqId());
  43. $this->assertNotNull($response->xLog());
  44. $this->assertNotNull($response->error);
  45. }
  46. public function testDeleteTimeout()
  47. {
  48. $reqOpt = new RequestOptions();
  49. $reqOpt->timeout = 1;
  50. $response = Client::delete('localhost:9000/timeout.php', array(), $reqOpt);
  51. $this->assertEquals(-1, $response->statusCode);
  52. }
  53. public function testPost()
  54. {
  55. $response = Client::post('qiniu.com', null);
  56. $this->assertEquals(200, $response->statusCode);
  57. $this->assertNotNull($response->body);
  58. $this->assertNull($response->error);
  59. }
  60. public function testPostQiniu()
  61. {
  62. $response = Client::post('upload.qiniu.com', null);
  63. $this->assertEquals(400, $response->statusCode);
  64. $this->assertNotNull($response->body);
  65. $this->assertNotNull($response->xReqId());
  66. $this->assertNotNull($response->xLog());
  67. $this->assertNotNull($response->error);
  68. }
  69. public function testPostTimeout()
  70. {
  71. $reqOpt = new RequestOptions();
  72. $reqOpt->timeout = 1;
  73. $response = Client::post('localhost:9000/timeout.php', null, array(), $reqOpt);
  74. $this->assertEquals(-1, $response->statusCode);
  75. }
  76. public function testPut()
  77. {
  78. $response = Client::PUT('uc.qbox.me/bucketTagging', null);
  79. $this->assertEquals(401, $response->statusCode);
  80. $this->assertNotNull($response->body);
  81. $this->assertNotNull($response->error);
  82. }
  83. public function testPutQiniu()
  84. {
  85. $response = Client::put('uc.qbox.me/bucketTagging', null);
  86. $this->assertEquals(401, $response->statusCode);
  87. $this->assertNotNull($response->body);
  88. $this->assertNotNull($response->xReqId());
  89. $this->assertNotNull($response->xLog());
  90. $this->assertNotNull($response->error);
  91. }
  92. public function testPutTimeout()
  93. {
  94. $reqOpt = new RequestOptions();
  95. $reqOpt->timeout = 1;
  96. $response = Client::put('localhost:9000/timeout.php', null, array(), $reqOpt);
  97. $this->assertEquals(-1, $response->statusCode);
  98. }
  99. }