mirror of
https://github.com/pestphp/pest.git
synced 2026-07-22 01:20:03 +02:00
feat: validation expectations (#1762)
* feat: add validation expectations for IP, MAC, hostname, domain, base64, and hexadecimal * improvements * improvements
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function (): void {
|
||||
expect('example.com')->toBeDomain() // standard domain
|
||||
->and('sub.example.com')->toBeDomain() // subdomain
|
||||
->and('my-host.io')->toBeDomain() // with hyphen
|
||||
->and('example.co.uk')->toBeDomain(); // multi-level TLD
|
||||
});
|
||||
|
||||
test('failures', function (): void {
|
||||
expect('example')->toBeDomain();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with leading dot', function (): void {
|
||||
expect('.example.com')->toBeDomain();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with invalid type', function (): void {
|
||||
expect([])->toBeDomain();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
|
||||
test('failures with custom message', function (): void {
|
||||
expect('example')->toBeDomain('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function (): void {
|
||||
expect('example.com')->not->toBeDomain();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
Reference in New Issue
Block a user