123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- use PHPUnit\Framework\TestCase;
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/6/23
- * Time: 下午10:21
- */
- define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_ROOT_PATH . '/helper/relation_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/performance_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
- class testRelationHelper extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testUpContactsA()
- {
- //36490
- $contacts = array('13911129868','13911129869','13911129870','13911129871','13911129867','15618951806','18612396521');
- relation_helper::onUpContacts(36490,'13911129867','江海苗',$contacts);
- }
- public function testUpContactsB()
- {
- //36490
- $contacts = array('13911129867','13911129869','13911129870','13911129872');
- relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
- }
- public function testOnLogin()
- {
- relation_helper::onLogin(36490);
- relation_helper::onLogin(36511);
- }
-
- public function testUpContactsC()
- {
- try
- {
- $contacts = '%5B%22178-0211-8910%22%2C%22182-6227-3057%22%2C%22189-6195-0030%22%5D';
- $contacts = session_helper::parse_contacts($contacts);
- relation_helper::onUpContacts(36511,'18612396521','秦梦洁',$contacts);
- } catch (Exception $ex) {
- echo $ex->getMessage();
- }
- }
- public function testMakeType()
- {
- $reg = '/make_type=(\d+)/i';
- $ret = preg_match($reg, '发送红包,红包单号: xxxxxx make_type=6', $arr);
- }
- public function testFollower()
- {
- $follower = relation_helper::follower(36490);
- if(!empty($follower)) {
- //$follower = self::separate_page($follower,$pages);
- $members = Model('member')->field('*')->where(array('member_id' => array('in',$follower)))->limit(false)->select();
- $desc = array();
- foreach ($members as $val) {
- $info = new member_info($val);
- }
- //return self::outsuccess(array('followers' => $follower,'mem_desc' => , 'mobile_page' => mobile_page($pages)));
- }
- }
- public function testDate()
- {
- $title = strftime("熊猫美妆%m月%d日红包风云榜",1469030400);
- }
- public function testSort()
- {
- $mod = Model('member_relation');
- $item = $mod->field('*')->where(array('member_mobile' => '13911129867'))->find();
- $mobiles = unserialize($item['unbuild_mobiles']);
- // perfor_start();
- // for($i = 0; $i < 10000; ++$i) {
- // sort($mobiles);
- // }
- // perfor_end("testSort","string sort");
- foreach ($mobiles as $mobile) {
- $iMobiles[] = intval($mobile);
- }
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- sort($iMobiles);
- }
- perfor_end("testSort","int sort");
- $len = count($iMobiles);
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $pos = $i % $len;
- $val = $iMobiles[$pos];
- //algorithm::array_erase($iMobiles,$pos);
- $pos = algorithm::lower_bonud($iMobiles,$val);
- //algorithm::array_insert($iMobiles,$pos,$val);
- }
- perfor_end("testSort","int sort");
- echo perfor_log();
- }
- public function testArrayInsert()
- {
- $x = array(1,3,5,9,10);
- $pos = algorithm::lower_bonud($x,3);
- $posx = algorithm::upper_bound($x,3);
- $y = algorithm::array_insert($x,$pos,0);
- $pos = algorithm::lower_bonud($x,4);
- $posx = algorithm::upper_bound($x,4);
- //$find = algorithm_helper::binary_search($x,0);
- }
- public function testLowerbound()
- {
- //$x = array(1,3,5,9,10);
- // $x = array(39625);
- $x = ['0','1','2'];
- $find = algorithm::binary_search($x,1);
- // $find = algorithm::binary_search($x,0);
- // $find = algorithm::binary_search($x,39625);
- // $pos = algorithm::lower_bonud($x,39625);
- // $pos = algorithm::lower_bonud($x,2);
- // $pos = algorithm::lower_bonud($x,3);
- // $pos = algorithm::lower_bonud($x,14);
- }
- public function testUpper()
- {
- $x = array(1,3,5,9,10);
- $pos = algorithm::upper_bound($x,0);
- $pos = algorithm::upper_bound($x,2);
- $pos = algorithm::upper_bound($x,3);
- $pos = algorithm::upper_bound($x,14);
- }
- public function testRelation()
- {
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $mod = Model('member_relation');
- $mod->findByMobile('13911129867');
- }
- perfor_end("testRelation","10000 findByMobile");
- $mod = Model('member_relation');
- $item = $mod->findByMobile('13911129867');
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- unserialize($item['unbuild_mobiles']);
- }
- perfor_end("testRelation","10000 unserialize");
- perfor_start();
- for($i = 0; $i < 10000; ++$i) {
- $relation = new \relation\mem_relation(36490);
- //$relation->pass_subscribe();
- }
- perfor_end("testRelation","10000 pass_subscribe");
- echo perfor_log();
- }
- public function testInitInvitors()
- {
- $path = BASE_DATA_PATH . "/mobile/invitors.txt";
- $file = fopen($path,'r');
- if(!is_resource($file)) {
- Log::record(__METHOD__ . " file is not exist",Log::ERR);
- return false;
- }
- while(!feof($file)) {
- $line = fgets($file);
- $kv = preg_split('/,/',$line);
- if(count($kv) != 2) continue;
- $key = trim($kv[0]);
- $val = trim($kv[1]);
- $this->update_invitor($key,$val);
- }
- fclose($file);
- }
- private function update_invitor($invitor,$user)
- {
- if(empty($invitor)) return false;
- $mod = Model('member');
- $invitor_info = $mod->where(['member_mobile' => $invitor])->find();
- if(empty($invitor_info)) return false;
- $member_id = intval($invitor_info['member_id']);
- $user_info = $mod->where(['member_mobile' => $user])->find();
- if(empty($user_info)) return false;
- $inviter_id = intval($user_info['inviter_id']);
- if($inviter_id > 0) return false;
- $ret = $mod->where(['member_mobile' => $user])->update(['inviter_id' => $member_id]);
- if($ret == false) {
- Log::record(__METHOD__ . " update {$user} invitor id err",Log::ERR);
- }
- else {
- Log::record(__METHOD__ . " update {$user} invitor id success",Log::DEBUG);
- }
- }
- public function testSeralize()
- {
- $stdout = fopen('php://stdout', 'w');
- $x = 'a:97:{i:0;i:36486;i:1;i:36487;i:2;i:36492;i:3;i:36628;i:4;i:37214;i:5;i:37234;i:6;i:37378;i:7;i:37623;i:8;i:37629;i:9;i:38606;i:10;i:38610;i:11;i:38647;i:12;i:38671;i:13;i:39086;i:14;i:39090;i:15;i:39187;i:16;i:39262;i:17;i:39285;i:18;i:39286;i:19;i:39287;i:20;i:39290;i:21;i:39302;i:22;i:39303;i:23;i:39304;i:24;i:39306;i:25;i:39307;i:26;i:39308;i:27;i:39309;i:28;i:39311;i:29;i:39313;i:30;i:39314;i:31;i:39316;i:32;i:39318;i:33;i:39319;i:34;i:39320;i:35;i:39321;i:36;i:39323;i:37;i:39328;i:38;i:39330;i:39;i:39338;i:40;i:39339;i:41;i:39350;i:42;i:39351;i:43;i:39352;i:44;i:39353;i:45;i:39391;i:46;i:39392;i:47;i:39398;i:48;i:39404;i:49;i:39410;i:50;i:39411;i:51;i:39412;i:52;i:39413;i:53;i:39414;i:54;i:39416;i:55;i:39417;i:56;i:39418;i:57;i:39419;i:58;i:39421;i:59;i:39422;i:60;i:39426;i:61;i:39433;i:62;i:39447;i:63;i:39459;i:64;i:39461;i:65;i:39462;i:66;i:39463;i:67;i:39465;i:68;i:39466;i:69;i:39471;i:70;i:39502;i:71;i:39517;i:72;i:39629;i:73;i:39632;i:74;i:39633;i:75;i:39634;i:76;i:39635;i:77;i:39636;i:78;i:39637;i:79;i:39638;i:80;i:39639;i:81;i:39646;i:82;i:39651;i:83;i:39652;i:84;i:39657;i:85;i:39659;i:86;i:39671;i:87;i:39676;i:88;i:39677;i:89;i:39678;i:90;i:39679;i:91;i:39680;i:92;i:39681;i:93;i:39682;i:94;i:39686;i:95;i:39687;i:96;i:39688;}';
- $start = microtime(true);
- for($i = 0; $i < 10000;$i++) {
- $y = unserialize($x);
- }
- $period = microtime(true) - $start;
- fwrite($stdout,"unserialize use time={$period}\n");
- $x = implode(',',$y);
- $start = microtime(true);
- for($i = 0; $i < 10000;$i++) {
- $y = explode(',',$x);
- }
- $period = microtime(true) - $start;
- fwrite($stdout,"explode use time={$period}\n");
- }
- public function testUnsubscribe()
- {
- $l = new relation\mem_relation(39668);
- $l->unsubscribe(39653);
- $r = new relation\mem_relation(39653);
- $r->unsubscribe(39668);
- }
- }
|