TestDispatcher.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare(strict_types=1);
  3. define('APP_ID', 'test');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
  9. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  10. require_once(BASE_CORE_PATH . '/framework/function/http.php');
  11. use PHPUnit\Framework\TestCase;
  12. const LocalTest = 1;
  13. const NetTest = 2;
  14. const CurrentTest = LocalTest;
  15. class TestDispatcher extends TestCase
  16. {
  17. private $mMchid;
  18. public static function setUpBeforeClass() : void
  19. {
  20. Base::run_util();
  21. }
  22. public function __construct(?string $name = null, array $data = [], $dataName = '')
  23. {
  24. parent::__construct($name, $data, $dataName);
  25. if (CurrentTest == LocalTest) {
  26. $this->mMchid = 1;
  27. } else {
  28. $this->mMchid = 1092;
  29. }
  30. }
  31. public function testPushMessage()
  32. {
  33. foreach (range(1,2000,1) as $i) {
  34. queue\DispatcherClient::instance()->push('xxx',$i);
  35. }
  36. }
  37. public function testAdd()
  38. {
  39. foreach (range(1,2000,1) as $i) {
  40. queue\DispatcherClient::instance()->push('add',[]);
  41. }
  42. }
  43. public function testNotify()
  44. {
  45. $logic = Logic('queue');
  46. $logic->NotifyMerchantComplete(['order_id' => 6462,'manual' => true]);
  47. }
  48. public function testAddoil()
  49. {
  50. foreach (range(1,2000,1) as $i) {
  51. queue\DispatcherClient::instance()->push('add',$this->make_order());
  52. }
  53. }
  54. public function testAddO()
  55. {
  56. foreach (range(1,1,1) as $i) {
  57. queue\DispatcherClient::instance()->push('add',$this->make_order());
  58. }
  59. }
  60. public function testAddH()
  61. {
  62. foreach (range(1,50000,1) as $i) {
  63. queue\DispatcherClient::instance()->push('add',$this->make_order());
  64. }
  65. }
  66. public function testGoods()
  67. {
  68. $goods = refill\RefillFactory::instance()->goods();
  69. $result = [];
  70. foreach ($goods as $type => $specs)
  71. {
  72. if($type == mtopcard\SinopecCard || $type == mtopcard\PetroChinaCard) {
  73. foreach ($specs as $spec) {
  74. $result['oil_amount'][] = $spec;
  75. }
  76. }
  77. else {
  78. $result['phone_amount'][] = $spec;
  79. }
  80. }
  81. return $result;
  82. }
  83. private function make_order()
  84. {
  85. $mchid = 1092;//
  86. // $mchid = $this->mMchid;
  87. $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
  88. $buyer_id = intval($mchinfo['admin_id']);
  89. $params = [ 'mchid' => $mchid,
  90. 'buyer_id' => $buyer_id,
  91. 'amount' => 100,
  92. 'card_no' => 15120035568,
  93. 'mch_order' => $this->make_sn(),
  94. 'notify_url' => 'https://www.xyzshops.cn/mobile/signature.php'];
  95. return $params;
  96. }
  97. private function make_sn()
  98. {
  99. return mt_rand(1000, 9999)
  100. . sprintf('%010d', time())
  101. . sprintf('%06d', (float)microtime() * 1000000);
  102. }
  103. public function testCurl()
  104. {
  105. Swoole\Coroutine\run(function () {
  106. $curl = curl_init();
  107. var_dump($curl, (int) $curl);
  108. //resource(4) of type (Swoole-Coroutine-cURL Handle)
  109. //int(4)
  110. $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
  111. Log::record("recv size=" . strlen($resp), Log::DEBUG);
  112. });
  113. }
  114. public function testDefine()
  115. {
  116. $x = MASTER_DBHOST . 'xxx';
  117. }
  118. public function testPolicy()
  119. {
  120. $key = "common_phone_speed_";
  121. }
  122. }