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

147 heartbeat not working anymore #149

Merged
merged 2 commits into from
Jul 5, 2024
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
30 changes: 27 additions & 3 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 @@ -38,6 +38,10 @@ class HeartBeat
* @var int The port you want to verify
*/
protected $port;
/**
* @var ?string The path to append
*/
protected $path;

/**
* @var int The timeout in seconds
Expand All @@ -59,12 +63,13 @@ class HeartBeat
* @param int $port
* @param int $timeout
*/
public function __construct(?string $host = null, int $port = Vies::VIES_PORT, 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);
}

$this->setPath($path);
$this->setPort($port);
$this->setTimeout($timeout);
}
Expand Down Expand Up @@ -92,6 +97,25 @@ public function setHost(string $host): self
return $this;
}

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

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

return $this;
}

/**
* @return int
*/
Expand Down Expand Up @@ -177,7 +201,7 @@ private function readContents($handle): array
throw new \InvalidArgumentException('Expecting a resource to be provided');
}
$response = '';
$uri = sprintf('%s://%s/', Vies::VIES_PROTO, $this->host);
$uri = sprintf('%s://%s%s', Vies::VIES_PROTO, $this->host, $this->path);
$stream = [
'GET ' . $uri . ' HTTP/1.0',
'Host: ' . $this->host,
Expand Down
3 changes: 2 additions & 1 deletion src/Vies/Vies.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Vies
const VIES_PROTO = 'https';
const VIES_DOMAIN = 'ec.europa.eu';
const VIES_PORT = 443;
const VIES_PATH = '/taxation_customs/vies';
const VIES_WSDL = '/taxation_customs/vies/checkVatService.wsdl';
const VIES_TEST_WSDL = '/taxation_customs/vies/checkVatTestService.wsdl';
const VIES_EU_COUNTRY_TOTAL = 28;
Expand Down Expand Up @@ -242,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);
$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