Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/Domain/Value/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function __construct(array $values)

Assert::keyExists($values, 'path');

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KristianH i am not so happy with this. Its too generic. Maybe something like The value of key "path" must be an trimmed non empty string

}

$this->path = $path ?? null;
Expand Down
14 changes: 14 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,18 @@ public function pathKeyMustExist(): void
new Link($values);
}

#[DataProviderExternal(StringProvider::class, 'blank')]
#[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