Skip to content

Commit

Permalink
DEFAULT_TIMEOUT made public, argument moved to last position, tests f…
Browse files Browse the repository at this point in the history
…ixed
  • Loading branch information
Jordy Verschoor authored and DragonBe committed Jul 5, 2024
1 parent 5f5fd55 commit a9da48c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/Vies/HeartBeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class HeartBeat
{
private const DEFAULT_TIMEOUT = 10;
public const DEFAULT_TIMEOUT = 10;

/**
* @var string The host you want to verify
Expand All @@ -39,7 +39,7 @@ class HeartBeat
*/
protected $port;
/**
* @var string The path to append
* @var ?string The path to append
*/
protected $path;

Expand All @@ -63,7 +63,7 @@ class HeartBeat
* @param int $port
* @param int $timeout
*/
public function __construct(?string $host = null, int $port = Vies::VIES_PORT, ?string $path = null, int $timeout = self::DEFAULT_TIMEOUT)
public function __construct(?string $host = null, int $port = Vies::VIES_PORT, int $timeout = self::DEFAULT_TIMEOUT, ?string $path = null)
{
if (null !== $host) {
$this->setHost($host);
Expand Down Expand Up @@ -98,18 +98,18 @@ public function setHost(string $host): self
}

/**
* @return string
* @return ?string
*/
public function getPath(): string
public function getPath(): ?string
{
return $this->path;
}

/**
* @param string $path
* @param ?string $path
* @return self
*/
public function setPath(string $path): self
public function setPath(?string $path = null): self
{
$this->path = $path;

Expand Down
2 changes: 1 addition & 1 deletion src/Vies/Vies.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function setOptions(array $options): self
*/
public function getHeartBeat(): HeartBeat
{
$this->heartBeat = $this->heartBeat ?? new HeartBeat(self::VIES_DOMAIN, self::VIES_PORT, self::VIES_PATH);
$this->heartBeat = $this->heartBeat ?? new HeartBeat(self::VIES_DOMAIN, self::VIES_PORT, HeartBeat::DEFAULT_TIMEOUT, self::VIES_PATH);

return $this->heartBeat;
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Vies/HeartBeatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public function testVerifyServicesIsDown()
public function socketProvider(): array
{
return [
'Non-existing socket on localhost' => ['127.0.0.1', -1, 10, false],
'Socket 443 on ec.europe.eu' => [Vies::VIES_DOMAIN, Vies::VIES_PORT, 10, true],
'Non-existing socket on localhost' => ['127.0.0.1', -1, 10, null, false],
'Socket 443 on ec.europe.eu' => [Vies::VIES_DOMAIN, Vies::VIES_PORT, 10, null, false],
'Socket 443 on ec.europe.eu'.Vies::VIES_PATH => [Vies::VIES_DOMAIN, Vies::VIES_PORT, 10, Vies::VIES_PATH, true],
];
}

Expand All @@ -124,10 +125,10 @@ public function socketProvider(): array
* @covers ::getSecuredResponse
* @covers ::readContents
*/
public function testIsAliveUsingSockets($host, $port, $timeout, $expectedResult)
public function testIsAliveUsingSockets($host, $port, $timeout, $path, $expectedResult)
{
HeartBeat::$testingEnabled = false;
$heartBeat = new HeartBeat($host, $port, $timeout);
$heartBeat = new HeartBeat($host, $port, $timeout, $path);
$actualResult = $heartBeat->isAlive();
$this->assertSame($expectedResult, $actualResult);
}
Expand Down

0 comments on commit a9da48c

Please sign in to comment.