diff --git a/src/EndpointIdentifier.php b/src/EndpointIdentifier.php index ab26c60..e91a102 100644 --- a/src/EndpointIdentifier.php +++ b/src/EndpointIdentifier.php @@ -19,7 +19,7 @@ class EndpointIdentifier implements EndpointInterface public function __construct(string $method, string $version, string $package, ?string $apiAction = null) { $this->method = strtoupper($method); - if ($this->checkVersionFormat($version) === false) { + if (strpos($version, '/') !== false) { throw new InvalidArgumentException('Version must have semantic numbering. For example "1", "1.1", "0.13.2" etc.'); } $this->version = $version; @@ -54,9 +54,4 @@ public function getUrl(): string { return "v{$this->version}/{$this->package}/{$this->apiAction}"; } - - private function checkVersionFormat(string $version): bool - { - return (preg_match('/^(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*)){0,2}$/', $version) === 1); - } } diff --git a/tests/EndpoinIdentifierTest.php b/tests/EndpoinIdentifierTest.php index 01a44fb..26d5c9f 100644 --- a/tests/EndpoinIdentifierTest.php +++ b/tests/EndpoinIdentifierTest.php @@ -36,11 +36,18 @@ public function testSimpleUrl() public function testSupportedVersions() { - new EndpointIdentifier('GET', '0', 'core', 'show'); - new EndpointIdentifier('GET', '1', 'core', 'show'); - new EndpointIdentifier('GET', '1.0', 'core', 'show'); - new EndpointIdentifier('GET', '1.1', 'core', 'show'); - new EndpointIdentifier('GET', '1.33', 'core', 'show'); + $endpoint = new EndpointIdentifier('GET', '0', 'core', 'show'); + $this->assertEquals('v0/core/show', $endpoint->getUrl()); + $endpoint = new EndpointIdentifier('GET', '1', 'core', 'show'); + $this->assertEquals('v1/core/show', $endpoint->getUrl()); + $endpoint = new EndpointIdentifier('GET', '1.0', 'core', 'show'); + $this->assertEquals('v1.0/core/show', $endpoint->getUrl()); + $endpoint = new EndpointIdentifier('GET', '1.1', 'core', 'show'); + $this->assertEquals('v1.1/core/show', $endpoint->getUrl()); + $endpoint = new EndpointIdentifier('GET', '1.33', 'core', 'show'); + $this->assertEquals('v1.33/core/show', $endpoint->getUrl()); + $endpoint = new EndpointIdentifier('GET', '1.33-dev', 'core', 'show'); + $this->assertEquals('v1.33-dev/core/show', $endpoint->getUrl()); $endpoint = new EndpointIdentifier('GET', '0.33.43', 'core', 'show'); $this->assertEquals('v0.33.43/core/show', $endpoint->getUrl()); } @@ -48,6 +55,6 @@ public function testSupportedVersions() public function testFailVersion() { $this->expectException(InvalidArgumentException::class); - new EndpointIdentifier('GET', 'test', 'core', 'show'); + new EndpointIdentifier('GET', '1.0/dev', 'core', 'show'); } }