TestDispatcher.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 testAddoil()
  44. {
  45. foreach (range(1,1,1) as $i) {
  46. queue\DispatcherClient::instance()->push('add',$this->make_order());
  47. }
  48. }
  49. private function make_order()
  50. {
  51. $mchid = $this->mMchid;
  52. $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
  53. $buyer_id = intval($mchinfo['admin_id']);
  54. $params = [ 'mchid' => $this->mMchid,
  55. 'buyer_id' => $buyer_id,
  56. 'amount' => 50,
  57. 'card_no' => 13911129867,
  58. 'mch_order' => $this->make_sn(),
  59. 'notify_url' => 'https://www.xyzshops.cn/mobile/signature.php'];
  60. return $params;
  61. }
  62. private function make_sn()
  63. {
  64. return mt_rand(1000, 9999)
  65. . sprintf('%010d', time())
  66. . sprintf('%06d', (float)microtime() * 1000000);
  67. }
  68. public function testCurl()
  69. {
  70. Swoole\Coroutine\run(function () {
  71. $curl = curl_init();
  72. var_dump($curl, (int) $curl);
  73. //resource(4) of type (Swoole-Coroutine-cURL Handle)
  74. //int(4)
  75. $resp = http_request('https://www.xyzshops.cn/mobile/index.php?act=index&op=index&client_type=ios');
  76. Log::record("recv size=" . strlen($resp), Log::DEBUG);
  77. });
  78. }
  79. public function testDefine()
  80. {
  81. $x = MASTER_DBHOST . 'xxx';
  82. }
  83. }