Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize SwooleConfig to open open_mqtt_protocol by default #52

Merged
merged 3 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
]);
}
}