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

fix: change type from int to float for heartbeat period #70

Merged
merged 1 commit into from
Sep 12, 2020
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
8 changes: 4 additions & 4 deletions src/MySQLReplication/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
array $databasesOnly,
int $tableCacheSize,
array $custom,
int $heartbeatPeriod
float $heartbeatPeriod
) {
self::$user = $user;
self::$host = $host;
Expand Down Expand Up @@ -103,8 +103,8 @@ public static function validate(): void
ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE, ConfigException::TABLE_CACHE_SIZE_ERROR_CODE
);
}
if (0 !== self::$heartbeatPeriod && false === filter_var(
self::$heartbeatPeriod, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1, 'max_range' => 4294967]]
if (0.0 !== self::$heartbeatPeriod && false === (
self::$heartbeatPeriod >= 0.001 && self::$heartbeatPeriod <= 4294967.0
)) {
throw new ConfigException(
ConfigException::HEARTBEAT_PERIOD_ERROR_MESSAGE, ConfigException::HEARTBEAT_PERIOD_ERROR_CODE
Expand Down Expand Up @@ -215,7 +215,7 @@ public static function getEventsIgnore(): array
return self::$eventsIgnore;
}

public static function getHeartbeatPeriod(): int
public static function getHeartbeatPeriod(): float
{
return self::$heartbeatPeriod;
}
Expand Down
4 changes: 2 additions & 2 deletions src/MySQLReplication/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigBuilder
private $mariaDbGtid = '';
private $tableCacheSize = 128;
private $custom = [];
private $heartbeatPeriod = 0;
private $heartbeatPeriod = 0.0;

public function withUser(string $user): self
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public function withCustom(array $custom): self
/**
* @see https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
*/
public function withHeartbeatPeriod(int $heartbeatPeriod): self
public function withHeartbeatPeriod(float $heartbeatPeriod): self
{
$this->heartbeatPeriod = $heartbeatPeriod;

Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ public function shouldCheckEvent(): void
self::assertFalse(Config::checkEvent(4));
}

public function shouldCheckHeartbeatPeriodProvider(): array
{
return [
[0],
[0.0],
[0.001],
[4294967],
[2],
];
}

/**
* @test
* @dataProvider shouldCheckHeartbeatPeriodProvider
*/
public function shouldCheckHeartbeatPeriod($heartbeatPeriod): void
{
$config = (new ConfigBuilder())->withHeartbeatPeriod($heartbeatPeriod)->build();
$config::validate();

self::assertSame((float) $heartbeatPeriod, $config::getHeartbeatPeriod());
}

public function shouldValidateProvider(): array
{
return [
Expand Down