CommonClientTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace TencentCloud\Common;
  3. use \ArrayObject;
  4. use PHPUnit\Framework\TestCase;
  5. use TencentCloud\Common\CommonClient;
  6. use TencentCloud\Common\Profile\HttpProfile;
  7. use TencentCloud\Common\Profile\ClientProfile;
  8. use TencentCloud\Common\Exception\TencentCloudSDKException;
  9. final class CommonClientTest extends TestCase
  10. {
  11. public function testCallJsonWithEmptyBody()
  12. {
  13. $cred = new Credential(
  14. getenv("TENCENTCLOUD_SECRET_ID"),
  15. getenv("TENCENTCLOUD_SECRET_KEY")
  16. );
  17. $client = new CommonClient("cvm", "2017-03-12", $cred, "ap-guangzhou");
  18. $resp = $client->callJson(
  19. "DescribeInstances",
  20. new ArrayObject(),
  21. array(),
  22. );
  23. $this->assertTrue($resp["TotalCount"] >= 0);
  24. }
  25. public function testCallJson()
  26. {
  27. $cred = new Credential(
  28. getenv("TENCENTCLOUD_SECRET_ID"),
  29. getenv("TENCENTCLOUD_SECRET_KEY")
  30. );
  31. $client = new CommonClient("cvm", "2017-03-12", $cred, "ap-guangzhou");
  32. $resp = $client->callJson(
  33. "DescribeInstances",
  34. [
  35. "Filters" => [
  36. [
  37. "Name" => "zone",
  38. "Values" => ["ap-guangzhou-1", "ap-guangzhou-2"]
  39. ]
  40. ]
  41. ],
  42. null,
  43. );
  44. $this->assertTrue($resp["TotalCount"] >= 0);
  45. }
  46. public function testCallJsonGetFail()
  47. {
  48. $cred = new Credential(
  49. getenv("TENCENTCLOUD_SECRET_ID"),
  50. getenv("TENCENTCLOUD_SECRET_KEY")
  51. );
  52. $httpProfile = new HttpProfile();
  53. $httpProfile->setReqMethod("GET");
  54. $clientProfile = new ClientProfile();
  55. $clientProfile->setHttpProfile($httpProfile);
  56. $client = new CommonClient("cvm", "2017-03-12", $cred, "ap-guangzhou", $clientProfile);
  57. $this->expectException(TencentCloudSDKException::class);
  58. $this->expectExceptionMessage("Common client call doesn't support GET method");
  59. $resp = $client->callJson(
  60. "DescribeInstances",
  61. [
  62. "Filters" => [
  63. [
  64. "Name" => "zone",
  65. "Values" => ["ap-guangzhou-1", "ap-guangzhou-2"]
  66. ]
  67. ]
  68. ],
  69. array(),
  70. );
  71. }
  72. }