mirror of
https://github.com/pestphp/pest.git
synced 2026-07-21 17:10:03 +02:00
b49cd150c9
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>
25 lines
783 B
PHP
25 lines
783 B
PHP
<?php
|
|
|
|
use PHPUnit\Framework\ExpectationFailedException;
|
|
|
|
test('pass', function () {
|
|
expect('user@example.com')->toBeEmail()
|
|
->and('notanemail')->not->toBeEmail();
|
|
});
|
|
|
|
test('failures', function () {
|
|
expect('notanemail')->toBeEmail();
|
|
})->throws(ExpectationFailedException::class);
|
|
|
|
test('failures with custom message', function () {
|
|
expect('notanemail')->toBeEmail('oh no!');
|
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
|
|
|
test('failures with default message', function () {
|
|
expect('notanemail')->toBeEmail();
|
|
})->throws(ExpectationFailedException::class, 'Failed asserting that notanemail is an email address.');
|
|
|
|
test('not failures', function () {
|
|
expect('user@example.com')->not->toBeEmail();
|
|
})->throws(ExpectationFailedException::class);
|