Skip to content

chore: add exception message for invalid path value #68

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/Domain/Value/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(array $values)
Assert::keyExists($values, 'path');

if (null !== $values['path']) {
$path = TrimmedNonEmptyString::fromString($values['path'])->toString();
$path = TrimmedNonEmptyString::fromString($values['path'], 'The value of key "path" is invalid.')->toString();
}

$this->path = $path ?? null;
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Domain/Value/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace Storyblok\Api\Tests\Unit\Domain\Value;

use Ergebnis\DataProvider\StringProvider;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Storyblok\Api\Domain\Value\Link;
Expand Down Expand Up @@ -153,6 +155,19 @@ public function pathKeyMustExist(): void
new Link($values);
}

#[DataProviderExternal(StringProvider::class, 'blank')]
#[DataProviderExternal(StringProvider::class, 'empty')]
#[Test]
public function pathMustBeValidString(string $value): void
{
$values = self::faker()->linkResponse(['path' => $value]);

self::expectExceptionMessage('The value of key "path" is invalid.');
self::expectException(\InvalidArgumentException::class);

new Link($values);
}

#[Test]
public function isFolder(): void
{
Expand Down