Skip to content

Commit

Permalink
Naming and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Jun 28, 2023
1 parent a6bf51c commit eda5991
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Api/Plex/PlexApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/ValueObject/RelativeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/ValueObject/RelativeUrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace Tests\Unit\Movary\ValueObject;

use Movary\Util\Json;
use Movary\ValueObject\Exception\InvalidRelativeUrl;
use Movary\ValueObject\RelativeUrl;
use PHPUnit\Framework\TestCase;

/** @covers \Movary\ValueObject\RelativeUrl */
class RelativeUrlTest extends TestCase
{
public function testCreateThrowsExceptionIfUrlIsNotValid() : void
{
$this->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);
}
}
9 changes: 1 addition & 8 deletions tests/unit/ValueObject/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
Expand Down

0 comments on commit eda5991

Please sign in to comment.