HistoryTraitTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace AlibabaCloud\Client\Tests\Unit\Traits;
  3. use PHPUnit\Framework\TestCase;
  4. use AlibabaCloud\Client\AlibabaCloud;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use AlibabaCloud\Client\Exception\ClientException;
  7. /**
  8. * Class HistoryTraitTest
  9. *
  10. * @package AlibabaCloud\Client\Tests\Unit\Traits
  11. */
  12. class HistoryTraitTest extends TestCase
  13. {
  14. /**
  15. * @throws ClientException
  16. * @throws ServerException
  17. */
  18. public function testCountHistory()
  19. {
  20. AlibabaCloud::cancelMock();
  21. AlibabaCloud::forgetHistory();
  22. AlibabaCloud::rememberHistory();
  23. $header = ['X-Foo' => 'Bar'];
  24. $body = [
  25. 'Code' => 'code',
  26. 'Message' => 'message',
  27. ];
  28. AlibabaCloud::mockResponse(200, $header, $body);
  29. AlibabaCloud::mockResponse(200, $header, $body);
  30. AlibabaCloud::rpc()
  31. ->product('ecs')
  32. ->regionId('cn-hangzhou')
  33. ->request();
  34. AlibabaCloud::rpc()
  35. ->product('ecs')
  36. ->regionId('cn-hangzhou')
  37. ->request();
  38. self::assertCount(2, AlibabaCloud::getHistory());
  39. self::assertEquals(2, AlibabaCloud::countHistory());
  40. }
  41. /**
  42. * @depends testCountHistory
  43. */
  44. public function testFlushHistory()
  45. {
  46. AlibabaCloud::forgetHistory();
  47. self::assertCount(0, AlibabaCloud::getHistory());
  48. self::assertEquals(0, AlibabaCloud::countHistory());
  49. }
  50. /**
  51. * @throws ClientException
  52. * @throws ServerException
  53. */
  54. public function testNotRememberHistory()
  55. {
  56. AlibabaCloud::forgetHistory();
  57. AlibabaCloud::notRememberHistory();
  58. $header = ['X-Foo' => 'Bar'];
  59. $body = [
  60. 'Code' => 'code',
  61. 'Message' => 'message',
  62. ];
  63. AlibabaCloud::mockResponse(200, $header, $body);
  64. AlibabaCloud::mockResponse(200, $header, $body);
  65. AlibabaCloud::rpc()
  66. ->product('ecs')
  67. ->regionId('cn-hangzhou')
  68. ->request();
  69. AlibabaCloud::rpc()
  70. ->product('ecs')
  71. ->regionId('cn-hangzhou')
  72. ->request();
  73. self::assertCount(0, AlibabaCloud::getHistory());
  74. self::assertEquals(0, AlibabaCloud::countHistory());
  75. }
  76. }