add to be url expectation

This commit is contained in:
JonPurvis
2023-10-09 20:02:11 +01:00
parent 2ffafd445d
commit 5101b9dce3
3 changed files with 48 additions and 0 deletions

View File

@ -1142,4 +1142,20 @@ final class Expectation
return $this;
}
/**
* Asserts that the value is a url
*
* @return self<TValue>
*/
public function toBeUrl(string $message = ''): self
{
if ($message === '') {
$message = "Failed asserting that {$this->value} is a url.";
}
Assert::assertTrue(Str::isUrl((string) $this->value), $message);
return $this;
}
}

View File

@ -108,4 +108,12 @@ final class Str
{
return sprintf('`%s` → %s', $describeDescription, $testDescription);
}
/**
* Determine if a given value is a valid URL.
*/
public static function isUrl(string $value): bool
{
return (bool) filter_var($value, FILTER_VALIDATE_URL);
}
}