mirror of
https://github.com/pestphp/pest.git
synced 2026-07-24 10:30:03 +02:00
feat: add toBeEmail expectation (#1735)
Adds `toBeEmail()` backed by `filter_var(FILTER_VALIDATE_EMAIL)`. Mirrors the existing `toBeUrl()` pattern — no new dependencies, pure PHP. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1171,6 +1171,22 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is an email address.
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toBeEmail(string $message = ''): self
|
||||
{
|
||||
if ($message === '') {
|
||||
$message = "Failed asserting that {$this->value} is an email address.";
|
||||
}
|
||||
|
||||
Assert::assertTrue(Str::isEmail((string) $this->value), $message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the value is a url
|
||||
*
|
||||
|
||||
@@ -118,6 +118,14 @@ final class Str
|
||||
return sprintf(str_repeat('`%s` → ', count($describeDescriptions)).'%s', ...$descriptionComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid email address.
|
||||
*/
|
||||
public static function isEmail(string $value): bool
|
||||
{
|
||||
return (bool) filter_var($value, FILTER_VALIDATE_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given value is a valid URL.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user