From 6350c22832c24d609a439a03db600bbec5d4d04e Mon Sep 17 00:00:00 2001 From: Punyapal Shah Date: Mon, 20 Jul 2026 17:25:20 +0530 Subject: [PATCH] docs: document new string expectations --- expectations.md | 60 ++++++++++++++++++++++++++++++++++++++++++ pest5-now-available.md | 12 ++++++--- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/expectations.md b/expectations.md index fec0c84..6380171 100644 --- a/expectations.md +++ b/expectations.md @@ -109,6 +109,12 @@ With the Pest expectation API, you have access to an extensive collection of ind - [`toBeUrl()`](#expect-toBeUrl) - [`toBeUuid()`](#expect-toBeUuid) - [`toBeUlid()`](#expect-toBeUlid) +- [`toBeBase64()`](#expect-toBeBase64) +- [`toBeDomain()`](#expect-toBeDomain) +- [`toBeHexadecimal()`](#expect-toBeHexadecimal) +- [`toBeHostname()`](#expect-toBeHostname) +- [`toBeIpAddress()`](#expect-toBeIpAddress) +- [`toBeMacAddress()`](#expect-toBeMacAddress) @@ -856,6 +862,60 @@ This expectation ensures that `$value` is a ULID: expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid(); ``` + +### `toBeBase64()` + +This expectation ensures that `$value` is a valid base64-encoded string: + +```php +expect('Zm9vYmFy')->toBeBase64(); +``` + + +### `toBeDomain()` + +This expectation ensures that `$value` is a valid domain name: + +```php +expect('example.com')->toBeDomain(); +``` + + +### `toBeHexadecimal()` + +This expectation ensures that `$value` is a valid hexadecimal string: + +```php +expect('deadbeef')->toBeHexadecimal(); +``` + + +### `toBeHostname()` + +This expectation ensures that `$value` is a valid hostname: + +```php +expect('example.com')->toBeHostname(); +``` + + +### `toBeIpAddress()` + +This expectation ensures that `$value` is a valid IP address: + +```php +expect('192.168.1.1')->toBeIpAddress(); +``` + + +### `toBeMacAddress()` + +This expectation ensures that `$value` is a valid MAC address: + +```php +expect('00:1a:2b:3c:4d:5e')->toBeMacAddress(); +``` + ### `and($value)` diff --git a/pest5-now-available.md b/pest5-now-available.md index d1e9214..9a3eeba 100644 --- a/pest5-now-available.md +++ b/pest5-now-available.md @@ -196,16 +196,22 @@ If you add new test files before updating the timings, your tests still run — ## New Expectations -Pest 5 also brings a couple of new additions to the expectation API. Sometimes you may wish to assert that a value is a well-formed email address or a valid ULID — two checks common enough that writing them by hand quickly becomes tedious. +Pest 5 also brings new additions to the expectation API. Sometimes you may wish to assert that a value is a well-formed email address, a valid IP address, or a ULID — checks common enough that writing them by hand quickly becomes tedious. -Thankfully, Pest now provides `toBeEmail()` and `toBeUlid()` for exactly these cases: +Thankfully, Pest now provides `toBeEmail()`, `toBeUlid()`, `toBeIpAddress()`, `toBeMacAddress()`, `toBeHostname()`, `toBeDomain()`, `toBeBase64()`, and `toBeHexadecimal()` for exactly these cases: ```php expect('nuno@pestphp.com')->toBeEmail(); expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid(); +expect('192.168.1.1')->toBeIpAddress(); +expect('00:1a:2b:3c:4d:5e')->toBeMacAddress(); +expect('example.com')->toBeHostname(); +expect('example.co.uk')->toBeDomain(); +expect('Zm9vYmFy')->toBeBase64(); +expect('deadbeef')->toBeHexadecimal(); ``` -Of course, both expectations may be negated with `not`. To explore the full set of available matchers, check out the [Expectations documentation](/docs/expectations). +Of course, each of these expectations may be negated with `not`. To explore the full set of available matchers, check out the [Expectations documentation](/docs/expectations). ## On Top of PHP 8.4 & PHPUnit 13