From 3d99bd648f5cc998406dfdcf91ab84397d16ee7f Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Mon, 17 May 2021 11:43:11 +0800 Subject: [PATCH 1/3] Optimize SwooleConfig to open open_mqtt_protocol by default --- src/Config/ClientConfig.php | 6 ++++-- tests/Unit/ClientConfigTest.php | 18 ++++++++++++++++++ 2 files changed, 22 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..a502c7b 100644 --- a/tests/Unit/ClientConfigTest.php +++ b/tests/Unit/ClientConfigTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase; use Simps\MQTT\Client; +use Simps\MQTT\Config\AbstractConfig; use Simps\MQTT\Config\ClientConfig; use Simps\MQTT\Protocol\ProtocolInterface; @@ -45,4 +46,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 + ]); + } } From 1bfb94f620e463868ea70fc873703adaf8778dd7 Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Mon, 17 May 2021 11:44:19 +0800 Subject: [PATCH 2/3] remove --- tests/Unit/ClientConfigTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/ClientConfigTest.php b/tests/Unit/ClientConfigTest.php index a502c7b..e07cf76 100644 --- a/tests/Unit/ClientConfigTest.php +++ b/tests/Unit/ClientConfigTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Simps\MQTT\Client; -use Simps\MQTT\Config\AbstractConfig; use Simps\MQTT\Config\ClientConfig; use Simps\MQTT\Protocol\ProtocolInterface; From 8905c8afcd90504d0f71195fb25bc3bcc8e57aaa Mon Sep 17 00:00:00 2001 From: sy-records <52o@qq52o.cn> Date: Mon, 17 May 2021 11:55:52 +0800 Subject: [PATCH 3/3] Fix code style --- tests/Unit/ClientConfigTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/ClientConfigTest.php b/tests/Unit/ClientConfigTest.php index e07cf76..b33cd72 100644 --- a/tests/Unit/ClientConfigTest.php +++ b/tests/Unit/ClientConfigTest.php @@ -55,11 +55,11 @@ public function testSwooleDefaultConfig() ]); $config->setSwooleConfig([ 'open_mqtt_protocol' => false, - 'package_max_length' => 2 * 1024 * 1024 + 'package_max_length' => 2 * 1024 * 1024, ]); $this->assertEquals($config->getSwooleConfig(), [ 'open_mqtt_protocol' => false, - 'package_max_length' => 2 * 1024 * 1024 + 'package_max_length' => 2 * 1024 * 1024, ]); } }