Skip to content

Commit 65f6bc9

Browse files
committed
chore: add exception message for invalid path value
1 parent 006cdab commit 65f6bc9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Domain/Value/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(array $values)
7272
Assert::keyExists($values, 'path');
7373

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

7878
$this->path = $path ?? null;

tests/Unit/Domain/Value/LinkTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

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

17+
use Ergebnis\DataProvider\StringProvider;
18+
use PHPUnit\Framework\Attributes\DataProviderExternal;
1719
use PHPUnit\Framework\Attributes\Test;
1820
use PHPUnit\Framework\TestCase;
1921
use Storyblok\Api\Domain\Value\Link;
@@ -153,6 +155,19 @@ public function pathKeyMustExist(): void
153155
new Link($values);
154156
}
155157

158+
#[DataProviderExternal(StringProvider::class, 'blank')]
159+
#[DataProviderExternal(StringProvider::class, 'empty')]
160+
#[Test]
161+
public function pathMustBeValidString(string $value): void
162+
{
163+
$values = self::faker()->linkResponse(['path' => $value]);
164+
165+
self::expectExceptionMessage('The value of key "path" is invalid.');
166+
self::expectException(\InvalidArgumentException::class);
167+
168+
new Link($values);
169+
}
170+
156171
#[Test]
157172
public function isFolder(): void
158173
{

0 commit comments

Comments
 (0)