TestFriends.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/7/14
  6. * Time: 下午4:22
  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/search/tcp_client.php');
  11. require_once(BASE_ROOT_PATH . '/helper/message/publisher.php');
  12. class TestFriends extends PHPUnit_Framework_TestCase
  13. {
  14. public static function setUpBeforeClass()
  15. {
  16. Base::run_util();
  17. }
  18. public function testAddFollow()
  19. {
  20. $result = search\relation_client::instance()->add_follow(array('user_id' => 36490,'friends'=>[1,2,3,4,5]));
  21. $result = search\relation_client::instance()->add_follow(array('user_id' => 36490,'friends'=>[3,4,5,6,7]));
  22. }
  23. public function testDelFollow()
  24. {
  25. $result = search\relation_client::instance()->del_follow(array('user_id' => 36490,'friends'=>[1]));
  26. $result = search\relation_client::instance()->del_follow(array('user_id' => 36490,'friends'=>[3,4]));
  27. }
  28. public function testFetchFollow()
  29. {
  30. for ($i =0 ; $i < 10000; ++$i) {
  31. $result = search\relation_client::instance()->fetch_follow(array('user_id' => 36490));
  32. }
  33. }
  34. public function testAddSpecial()
  35. {
  36. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 7])));
  37. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 6])));
  38. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 9])));
  39. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 17])));
  40. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 16])));
  41. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 19])));
  42. }
  43. public function testDelSpecial()
  44. {
  45. $result = search\relation_client::instance()->add_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 9])));
  46. $result = search\relation_client::instance()->del_special(array('user_id' => 36490,'specials'=>array(['type' => 0,'spid' => 9])));
  47. }
  48. public function testFetchPub()
  49. {
  50. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => -1,'count'=> 1000,'type' => 1]);
  51. for ($i =0 ; $i < 10000; ++$i)
  52. {
  53. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => 11,'count'=> 10,'type' => 1]);
  54. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => 11,'count'=> 10,'type' => 0]);
  55. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => 9,'count'=> 10,'type' => 0]);
  56. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => 9,'count'=> 10,'type' => 1]);
  57. }
  58. }
  59. //publisher
  60. public function testAddFriend()
  61. {
  62. $publisher = new message\publisher();
  63. $publisher->add_follow(36490,[1,2,3,57]);
  64. }
  65. public function testDelFriend()
  66. {
  67. $publisher = new message\publisher();
  68. $publisher->del_follow(36490,[1,2,3,57]);
  69. }
  70. public function testAddSpecials()
  71. {
  72. $publisher = new message\publisher();
  73. $publisher->add_special(36490,array(['type' => 1, 'spid' =>1],['type' => 1,'spid' => 2],['type' => 1,'spid' => 3]));
  74. }
  75. public function testDelSpecials()
  76. {
  77. $publisher = new message\publisher();
  78. $publisher->del_special(36490,array(['type' => 1, 'spid' =>1],['type' => 1,'spid' => 2],['type' => 1,'spid' => 3]));
  79. }
  80. public function testAddInviter()
  81. {
  82. // search\relation_client::instance()->add_inviter(['user_id' => 39638,'inviter_id' => 39623]);
  83. // $result = search\relation_client::instance()->fetch_inviters(['user_id' => 39633]);
  84. $publisher = new message\publisher();
  85. $publisher->add_inviter(100,39623);
  86. $publisher->add_inviter(39634,39623);
  87. $publisher->add_inviter(39635,39623);
  88. $publisher->add_inviter(39636,39623);
  89. $publisher->add_inviter(39637,39623);
  90. $publisher->add_inviter(39639,39623);
  91. $result = search\relation_client::instance()->fetch_invitees(['user_id' => 39623]);
  92. }
  93. public function testFetchInviters()
  94. {
  95. $mod_member = Model('member');
  96. $items = $mod_member->where(['inviter_id' => ['gt',0]])->field('*')->limit(false)->select();
  97. foreach ($items as $item)
  98. {
  99. $user = intval($item['member_id']);
  100. $inviters = search\relation_client::instance()->fetch_inviters(['user_id' => $user]);
  101. $invitees = search\relation_client::instance()->fetch_invitees(['user_id' => $user]);
  102. echo implode(",",$inviters);
  103. echo "\n";
  104. echo implode("_",$invitees);
  105. echo "\n";
  106. }
  107. }
  108. public function testFollows()
  109. {
  110. $iRelation = new \relation\mem_relation(39623);
  111. $subscriber = $iRelation->subscriber();
  112. $follower = $iRelation->follower();
  113. $inviters = search\relation_client::instance()->fetch_follow(['user_id' => 39623]);
  114. $specials = search\relation_client::instance()->fetch_pri_special(['user_id' => 39623,'special_id' => -1,'count'=> 100,'type' => 1]);
  115. $specials_follow = search\relation_client::instance()->fetch_self_special(['user_id' => 39646,'special_id' => -1,'count'=> 100,'type' => 1]);
  116. $inviters = search\relation_client::instance()->fetch_follow(['user_id' => 39646]);
  117. }
  118. }