PutSetDeleteResultTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Core\OssException;
  4. use OSS\Http\ResponseCore;
  5. use OSS\Result\PutSetDeleteResult;
  6. class ResultTest extends \PHPUnit_Framework_TestCase
  7. {
  8. public function testNullResponse()
  9. {
  10. $response = null;
  11. try {
  12. new PutSetDeleteResult($response);
  13. $this->assertFalse(true);
  14. } catch (OssException $e) {
  15. $this->assertEquals('raw response is null', $e->getMessage());
  16. }
  17. }
  18. public function testOkResponse()
  19. {
  20. $header= array(
  21. 'x-oss-request-id' => '582AA51E004C4550BD27E0E4',
  22. 'etag' => '595FA1EA77945233921DF12427F9C7CE',
  23. 'content-md5' => 'WV+h6neUUjOSHfEkJ/nHzg==',
  24. 'info' => array(
  25. 'http_code' => '200',
  26. 'method' => 'PUT'
  27. ),
  28. );
  29. $response = new ResponseCore($header, "this is a mock body, just for test", 200);
  30. $result = new PutSetDeleteResult($response);
  31. $data = $result->getData();
  32. $this->assertTrue($result->isOK());
  33. $this->assertEquals("this is a mock body, just for test", $data['body']);
  34. $this->assertEquals('582AA51E004C4550BD27E0E4', $data['x-oss-request-id']);
  35. $this->assertEquals('595FA1EA77945233921DF12427F9C7CE', $data['etag']);
  36. $this->assertEquals('WV+h6neUUjOSHfEkJ/nHzg==', $data['content-md5']);
  37. $this->assertEquals('200', $data['info']['http_code']);
  38. $this->assertEquals('PUT', $data['info']['method']);
  39. }
  40. public function testFailResponse()
  41. {
  42. $response = new ResponseCore(array(), "", 301);
  43. try {
  44. new PutSetDeleteResult($response);
  45. $this->assertFalse(true);
  46. } catch (OssException $e) {
  47. }
  48. }
  49. public function setUp()
  50. {
  51. }
  52. public function tearDown()
  53. {
  54. }
  55. }