diff --git a/src/Api/Plex/PlexApi.php b/src/Api/Plex/PlexApi.php index c6b9f334..6ced6187 100644 --- a/src/Api/Plex/PlexApi.php +++ b/src/Api/Plex/PlexApi.php @@ -48,7 +48,7 @@ public function findPlexAccessToken(string $plexPinId, string $temporaryPlexClie 'code' => $temporaryPlexClientCode, ]; - $relativeUrl = RelativeUrl::createFromString('/pins/' . $plexPinId); + $relativeUrl = RelativeUrl::create('/pins/' . $plexPinId); try { $plexRequest = $this->plexTvClient->get($relativeUrl, $headers); @@ -67,7 +67,7 @@ public function findPlexAccount(PlexAccessToken $plexAccessToken) : ?PlexAccount 'X-Plex-Token' => $plexAccessToken->getPlexAccessTokenAsString() ]; - $relativeUrl = RelativeUrl::createFromString('/user'); + $relativeUrl = RelativeUrl::create('/user'); try { $accountData = $this->plexTvClient->get($relativeUrl, $headers); @@ -88,7 +88,7 @@ public function findPlexAccount(PlexAccessToken $plexAccessToken) : ?PlexAccount */ public function generatePlexAuthenticationUrl() : ?string { - $relativeUrl = RelativeUrl::createFromString('/pins'); + $relativeUrl = RelativeUrl::create('/pins'); try { $plexAuthenticationData = $this->plexTvClient->sendPostRequest($relativeUrl); diff --git a/src/ValueObject/RelativeUrl.php b/src/ValueObject/RelativeUrl.php index 438634c8..9bc61dbc 100644 --- a/src/ValueObject/RelativeUrl.php +++ b/src/ValueObject/RelativeUrl.php @@ -15,7 +15,7 @@ private function __construct(private readonly string $relativeUrl) //endregion instancing //region methods - public static function createFromString(string $url) : self + public static function create(string $url) : self { return new self($url); } @@ -33,7 +33,7 @@ public function jsonSerialize() : string private function ensureIsValidRelativeUrl(string $url) : void { if (str_starts_with($url, '/') === false || parse_url($url) === false) { - throw new InvalidRelativeUrl('Invalid relative url: ' . $url); + throw InvalidRelativeUrl::create($url); } } //endregion methods diff --git a/tests/unit/ValueObject/RelativeUrlTest.php b/tests/unit/ValueObject/RelativeUrlTest.php new file mode 100644 index 00000000..81c41f0f --- /dev/null +++ b/tests/unit/ValueObject/RelativeUrlTest.php @@ -0,0 +1,34 @@ +expectException(InvalidRelativeUrl::class); + $this->expectExceptionMessage('Not a valid relative url: not-valid'); + + RelativeUrl::create('not-valid'); + } + + public function testJsonSerialize() : void + { + $subject = RelativeUrl::create('/relativeUrl?q=a'); + + self::assertSame('"\/relativeUrl?q=a"', Json::encode($subject)); + } + + public function testToString() : void + { + $subject = RelativeUrl::create('/relativeUrl?q=a'); + + self::assertSame('/relativeUrl?q=a', (string)$subject); + } +} diff --git a/tests/unit/ValueObject/UrlTest.php b/tests/unit/ValueObject/UrlTest.php index 94b45481..fe6316ce 100644 --- a/tests/unit/ValueObject/UrlTest.php +++ b/tests/unit/ValueObject/UrlTest.php @@ -12,7 +12,7 @@ class UrlTest extends TestCase { public function testAppendRelativeUrl() : void { - $relativeUrl = RelativeUrl::createFromString('/relativeUrl?q=a'); + $relativeUrl = RelativeUrl::create('/relativeUrl?q=a'); $subject = Url::createFromString('https://movary.org/path'); @@ -22,13 +22,6 @@ public function testAppendRelativeUrl() : void ); } - public function testCreateFromString() : void - { - $subject = Url::createFromString('https://movary.org'); - - self::assertSame('https://movary.org', (string)$subject); - } - public function testCreateThrowsExceptionIfUrlIsNotValid() : void { $this->expectException(InvalidUrl::class);