Skip to content

Commit 0a00988

Browse files
committed
update
1 parent d2496fd commit 0a00988

5 files changed

Lines changed: 16 additions & 15 deletions

File tree

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
"phpunit/phpunit": "^9.6 | ^10.0",
3030
"phpstan/phpstan": "^1.11",
3131
"friendsofphp/php-cs-fixer": "^3.58",
32-
"illuminate/redis": "^9.0 | ^10.0 | ^11.0 | ^12.0",
33-
"workerman/redis": "^2.0"
32+
"workerman/redis": "^2.0",
33+
"workbunny/webman-shared-cache": "^0.6"
3434
},
3535
"suggest": {
3636
"ext-uuid": "For unique socket id. ",
37-
"illuminate/redis": "For redis storage. ",
38-
"workerman/redis": "For redis channel. "
37+
"webman/redis": "For redis storage. ",
38+
"workerman/redis": "For redis channel. ",
39+
"workbunny/webman-shared-cache": "For shared storage / channel. "
3940
},
4041
"autoload": {
4142
"psr-4": {

src/Channels/RedisChannel.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
class RedisChannel implements ChannelInterface
1414
{
15+
public static bool $test = false;
16+
1517
/**
1618
* @var Client|null
1719
*/
@@ -38,7 +40,7 @@ public function __construct(?string $redisChannel)
3840
if (!$config = config('redis')["plugin.workbunny.webman-push-server.$redisChannel"] ?? []) {
3941
throw new InvalidArgumentException("Redis channel [$redisChannel] not found. ");
4042
}
41-
try {
43+
if (!static::$test) {
4244
$client = new Client(sprintf('redis://%s:%s', $config['host'], $config['port']), $config['options'] ?? []);
4345
$client->connect();
4446
if ($passport = $config['password'] ?? null) {
@@ -48,10 +50,6 @@ public function __construct(?string $redisChannel)
4850
$client->select($database);
4951
}
5052
$this->_subClient = $client;
51-
} catch (\RuntimeException $e) {
52-
if ($e->getMessage() !== 'Timer can only be used in workerman running environment') {
53-
throw $e;
54-
}
5553
}
5654
$this->_pubClient = Redis::connection("plugin.workbunny.webman-push-server.$redisChannel")->client();
5755
}

src/Traits/ChannelMethods.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ trait ChannelMethods
3535
public static function channelConnect(string $channelKey = 'default'): ChannelInterface
3636
{
3737
if (!(static::$channels[$channelKey] ?? null)) {
38-
$handler = config("workbunny.webman-push-server.channel.$channelKey.handler");
39-
$channel = config("workbunny.webman-push-server.channel.$channelKey.channel");
38+
$handler = config("plugin.workbunny.webman-push-server.channel.$channelKey.handler");
39+
$channel = config("plugin.workbunny.webman-push-server.channel.$channelKey.channel");
4040
$handler = is_a($handler, ChannelInterface::class, true) ? new $handler($channel) : new RedisChannel(
4141
// 兼容旧版及其他可能的可选项
4242
$channelKey === 'default' ?

src/Traits/StorageMethods.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trait StorageMethods
4343
public static function getStorageClient(): StorageInterface
4444
{
4545
if(!self::$_storageClient instanceof StorageInterface){
46-
$handler = config('workbunny.webman-push-server.storage.handler');
46+
$handler = config('plugin.workbunny.webman-push-server.storage.handler');
4747
$handler = is_a($handler, StorageInterface::class, true) ? new $handler : new RedisStorage();
4848
self::$_storageClient = $handler;
4949
}

tests/BaseTestCase.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Webman\Config;
1919
use Webman\Route;
2020
use Workbunny\WebmanPushServer\ApiServer;
21+
use Workbunny\WebmanPushServer\Channels\RedisChannel;
2122
use Workbunny\WebmanPushServer\PushServer;
2223

2324

@@ -75,12 +76,13 @@ class_exists($bootstrap) and
7576
}
7677
}
7778
}
78-
// 取消workerman Timer中存在的pcntl_alarm(1),避免测试用例无法运行完整
79-
pcntl_alarm(0);
80-
8179
// 模拟启动服务
8280
static::$pushServer = new PushServer();
8381
static::$apiServer = new ApiServer();
82+
// 开启测试模式
83+
RedisChannel::$test = true;
84+
// 取消workerman Timer中存在的pcntl_alarm(1),避免测试用例无法运行完整
85+
pcntl_alarm(0);
8486
parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
8587
}
8688

0 commit comments

Comments
 (0)