Skip to content

Commit

Permalink
Optimize SwooleConfig to open open_mqtt_protocol by default (#52)
Browse files Browse the repository at this point in the history
* Optimize SwooleConfig to open open_mqtt_protocol by default

* remove

* Fix code style
  • Loading branch information
sy-records authored May 17, 2021
1 parent 3b6843b commit 73ac7ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Config/ClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class ClientConfig extends AbstractConfig
{
protected $clientId = '';

protected $swooleConfig = [];
protected $swooleConfig = [
'open_mqtt_protocol' => true,
];

protected $userName = '';

Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/ClientConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}

0 comments on commit 73ac7ac

Please sign in to comment.