From 73ac7ac200b794735c9eb86d462e828675f60a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Mon, 17 May 2021 11:59:30 +0800 Subject: [PATCH] Optimize SwooleConfig to open open_mqtt_protocol by default (#52) * Optimize SwooleConfig to open open_mqtt_protocol by default * remove * Fix code style --- src/Config/ClientConfig.php | 6 ++++-- tests/Unit/ClientConfigTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Config/ClientConfig.php b/src/Config/ClientConfig.php index 3e57d94..980a35e 100644 --- a/src/Config/ClientConfig.php +++ b/src/Config/ClientConfig.php @@ -19,7 +19,9 @@ class ClientConfig extends AbstractConfig { protected $clientId = ''; - protected $swooleConfig = []; + protected $swooleConfig = [ + 'open_mqtt_protocol' => true, + ]; protected $userName = ''; @@ -58,7 +60,7 @@ public function getSwooleConfig(): array public function setSwooleConfig(array $config): self { - $this->swooleConfig = $config; + $this->swooleConfig = array_merge($this->swooleConfig, $config); return $this; } diff --git a/tests/Unit/ClientConfigTest.php b/tests/Unit/ClientConfigTest.php index d12ed7b..b33cd72 100644 --- a/tests/Unit/ClientConfigTest.php +++ b/tests/Unit/ClientConfigTest.php @@ -45,4 +45,21 @@ public function testIsMQTT5() $this->assertTrue($config->isMQTT5()); $this->assertEquals($config->getProtocolLevel(), ProtocolInterface::MQTT_PROTOCOL_LEVEL_5_0); } + + public function testSwooleDefaultConfig() + { + $config = new ClientConfig(); + $config->setSwooleConfig([]); + $this->assertEquals($config->getSwooleConfig(), [ + 'open_mqtt_protocol' => true, + ]); + $config->setSwooleConfig([ + 'open_mqtt_protocol' => false, + 'package_max_length' => 2 * 1024 * 1024, + ]); + $this->assertEquals($config->getSwooleConfig(), [ + 'open_mqtt_protocol' => false, + 'package_max_length' => 2 * 1024 * 1024, + ]); + } }