diff --git a/src/Vies/HeartBeat.php b/src/Vies/HeartBeat.php index f12c1e0..2902f4b 100644 --- a/src/Vies/HeartBeat.php +++ b/src/Vies/HeartBeat.php @@ -28,7 +28,7 @@ */ class HeartBeat { - private const DEFAULT_TIMEOUT = 10; + public const DEFAULT_TIMEOUT = 10; /** * @var string The host you want to verify @@ -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 @@ -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); } @@ -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 */ @@ -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, diff --git a/src/Vies/Vies.php b/src/Vies/Vies.php index 3a4b7b9..85ba5f7 100644 --- a/src/Vies/Vies.php +++ b/src/Vies/Vies.php @@ -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; @@ -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; } diff --git a/tests/Vies/HeartBeatTest.php b/tests/Vies/HeartBeatTest.php index 2f9fc8a..48174bb 100644 --- a/tests/Vies/HeartBeatTest.php +++ b/tests/Vies/HeartBeatTest.php @@ -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], ]; } @@ -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); }