TestRoomSrv.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/12/14
  6. * Time: 下午4:59
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/helper/event_looper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/room/room_processor.php');
  12. require_once(BASE_ROOT_PATH . '/helper/room/proto_type.php');
  13. require_once(BASE_ROOT_PATH . '/helper/room/base_room.php');
  14. require_once(BASE_ROOT_PATH . '/helper/room/chat_room.php');
  15. require_once(BASE_ROOT_PATH . '/helper/room/chatwo.php');
  16. require_once(BASE_ROOT_PATH . '/helper/room/group_room.php');
  17. require_once(BASE_ROOT_PATH . '/helper/room/bargain_room.php');
  18. require_once(BASE_ROOT_PATH . '/helper/room/factory.php');
  19. require_once(BASE_ROOT_PATH . '/helper/room/room_client.php');
  20. class TestRoomSrv extends PHPUnit_Framework_TestCase
  21. {
  22. const room_id = 30;
  23. const creator = 36429;
  24. public static function setUpBeforeClass()
  25. {
  26. Base::run_util();
  27. }
  28. public function testBuildRoom()
  29. {
  30. $roomid=43;
  31. $processor = new room\room_processor();
  32. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','room' => self::room_id,'op' => 'build']));
  33. }
  34. public function testInviteRoom()
  35. {
  36. $invitee = 36507;
  37. $processor = new room\room_processor();
  38. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'invite','room' => self::room_id,'inviter' => $this->creator(self::room_id),'invitees' => [$invitee]]));
  39. }
  40. public function testLeaveRoom()
  41. {
  42. $user = 36507;
  43. $processor = new room\room_processor();
  44. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'leave','room' => self::room_id,'user' => $user]));
  45. }
  46. public function testListRoom()
  47. {
  48. $roomid=30;
  49. $processor = new room\room_processor();
  50. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','room' => $roomid,'op' => 'build']));
  51. $ret = $processor->onRequest(0,json_encode(["act" => 'access','op' => 'list']));
  52. }
  53. public function testRoomMessage()
  54. {
  55. $invitee = 36507;
  56. $processor = new room\room_processor();
  57. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'invite','room' => self::room_id,'inviter' => $this->creator(self::room_id),'invitees' => [$invitee]]));
  58. $ret = $processor->onRequest(0,json_encode(["act" => 'room','op' => 'message','room' => self::room_id,'user' => $invitee,'type' => 'text','content' => 'xxxxx']));
  59. }
  60. public function testChatwo()
  61. {
  62. $invitee = 36507;
  63. $processor = new room\room_processor();
  64. $ret = $processor->onRequest(0,json_encode(["act" => 'chatwo','op' => 'message','seq' => 1,
  65. 'from' => 36507,'to' => 36429,'type' => 'text','content' => 'hello world']));
  66. }
  67. public function testPush()
  68. {
  69. $invitee = 36507;
  70. $processor = new room\room_processor();
  71. $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'push','seq' => 1,'content' => 'hello world']));
  72. }
  73. private function creator($room_id)
  74. {
  75. $mod_room = Model('room');
  76. $params = $mod_room->getRoom($room_id);
  77. $rinfo = new room\base_info($params);
  78. return $rinfo->creator();
  79. }
  80. public function testBuild()
  81. {
  82. $client = new room\room_client("192.168.0.200",2001);
  83. for ($i = 0; $i < 100000; $i++) {
  84. $ret = $client->build(37);
  85. }
  86. }
  87. public function testMessage()
  88. {
  89. $user = 39623;
  90. $client = new room\room_client("192.168.0.200",2001);
  91. $ret = $client->build(37);
  92. for ($i = 0; $i < 100000; $i++) {
  93. $ret = $client->message(37,$user,'text','wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww');
  94. }
  95. }
  96. }