Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5686208

Browse files
committed
Add test case
1 parentc6705a2 commit5686208

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

‎tests/MainTest.php‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
finalclass MainTestextends TestCase
77
{
88

9-
publicfunctiontest():void
9+
publicfunctiontestSubscribe():void
1010
{
1111
$func =function () {
1212
$sub =new \Mix\Redis\Subscriber\Subscriber('127.0.0.1',6379,'',5);
@@ -31,6 +31,42 @@ public function test(): void
3131
}
3232
break;
3333
}
34+
$this->assertEquals($data->channel,'foo1');
35+
$this->assertEquals($data->payload,'foo1data');
36+
break;
37+
}
38+
$sub->close();
39+
};
40+
run($func);
41+
}
42+
43+
publicfunctiontestPsubscribe():void
44+
{
45+
$func =function () {
46+
$sub =new \Mix\Redis\Subscriber\Subscriber('127.0.0.1',6379,'',5);
47+
$sub->psubscribe('foo.*','bar');// 订阅失败将抛出异常
48+
$sub->psubscribe('foo1.*','bar1');
49+
$sub->punsubscribe('foo.*','bar');
50+
51+
go(function () {
52+
$redis =new \Redis();
53+
$redis->connect('127.0.0.1',6379);
54+
$redis->publish('foo.1','foodata');
55+
$redis->publish('foo1.1','foo1data');
56+
});
57+
58+
$chan =$sub->channel();
59+
while (true) {
60+
$data =$chan->pop();
61+
if (empty($data)) {// 手动close与redis异常断开都会导致返回false
62+
if (!$sub->closed) {
63+
// redis异常断开处理
64+
var_dump('Redis connection is disconnected abnormally');
65+
}
66+
break;
67+
}
68+
$this->assertEquals($data->pattern,'foo1.*');
69+
$this->assertEquals($data->channel,'foo1.1');
3470
$this->assertEquals($data->payload,'foo1data');
3571
break;
3672
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp