DeprecatedTraitTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Request;
  3. use AlibabaCloud\Client\Encode;
  4. use PHPUnit\Framework\TestCase;
  5. use AlibabaCloud\Client\Request\RpcRequest;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. /**
  8. * Class DeprecatedTraitTest
  9. *
  10. * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Unit\Request
  11. */
  12. class DeprecatedTraitTest extends TestCase
  13. {
  14. /**
  15. * @throws ClientException
  16. */
  17. public function testGetDomainParameter()
  18. {
  19. // Setup
  20. $request = new RpcRequest();
  21. // Assert
  22. self::assertEquals([], isset($request->options['form_params']) ? $request->options['form_params'] : []);
  23. }
  24. /**
  25. * @throws ClientException
  26. */
  27. public function testGetLocationEndpointType()
  28. {
  29. // Setup
  30. $request = new RpcRequest();
  31. // Assert
  32. self::assertEquals('openAPI', $request->endpointType);
  33. $endpointType = 'test';
  34. // Test
  35. $request->endpointType = $endpointType;
  36. // Assert
  37. self::assertEquals($endpointType, $request->endpointType);
  38. }
  39. /**
  40. * @throws ClientException
  41. */
  42. public function testGetLocationServiceCode()
  43. {
  44. // Setup
  45. $request = new RpcRequest();
  46. // Assert
  47. self::assertEquals(null, $request->serviceCode);
  48. $content = 'test';
  49. // Test
  50. $request->serviceCode = $content;
  51. // Assert
  52. self::assertEquals($content, $request->serviceCode);
  53. }
  54. /**
  55. * @dataProvider encode
  56. *
  57. * @param array $array
  58. * @param string $expected
  59. */
  60. public function testEncode(array $array, $expected)
  61. {
  62. // Assert
  63. self::assertEquals(
  64. $expected,
  65. Encode::create($array)->toString()
  66. );
  67. }
  68. /**
  69. * @return array
  70. */
  71. public function encode()
  72. {
  73. return [
  74. [
  75. [1, 2, 3],
  76. '0=1&1=2&2=3',
  77. ],
  78. [
  79. [
  80. 'a' => 'a',
  81. 'b' => 'b',
  82. 'c' => 'c',
  83. ],
  84. 'a=a&b=b&c=c',
  85. ],
  86. [
  87. [
  88. 'a' => 'a',
  89. 'b' => 'b',
  90. 3,
  91. 4,
  92. ],
  93. 'a=a&b=b&0=3&1=4',
  94. ],
  95. [
  96. [
  97. 'a' => 'a',
  98. 'b' => 'b ',
  99. 3,
  100. 4,
  101. ],
  102. 'a=a&b=b%20&0=3&1=4',
  103. ],
  104. ];
  105. }
  106. }